Python Postgres插入错误

时间:2018-06-06 06:17:41

标签: python python-3.x postgresql psycopg2

大家好我必须从python中为我的postgresql表批量输入循环代码。我已经尝试了所有可能的方法来输入数据。但我无法做到。

        data = count,ipaddress,asn_value,asno,aso,sock_value,sock,datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
        print (data)
        cur.execute('insert into dataoldnew values (%s,%s,%s,%s,%s,%s,%s,%s)',data)
        print("Records created successfully")
        conn.close()

调试

data= (1, '217.76.156.252', 1, 8560, '1&1 Internet SE', 0, 0, '2018-06-06 11:35')

错误

Exception in callback task2() at mining.py:43
handle: <Handle task2() at mining.py:43>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/events.py", line 125, in _run
    self._callback(*self._args)
  File "mining.py", line 31, in wrapper
    ret = func(*args, **kwargs)
  File "mining.py", line 149, in task2
    cur.execute('insert into dataoldnew values (%s,%s,%s,%s,%s,%s,%s,%s)',data)
psycopg2.DataError: invalid input syntax for integer: "217.76.156.252"
LINE 1: insert into dataoldnew values (1,'217.76.156.252',1,8560,'1&...
                                         ^

我在postgresql中有一个表。

Postgres表架构

-- Table: public.dataoldnew

-- DROP TABLE public.dataoldnew;

CREATE TABLE public.dataoldnew
(
  index bigint,
  idtemp bigint,
  ipaddress text,
  "timestamp" text,
  values_asn bigint,
  values_aso text,
  values_host_name text,
  values_host_name_true_false bigint
)
WITH (
  OIDS=FALSE
);
ALTER TABLE public.dataoldnew
  OWNER TO aditya;

-- Index: public.ix_dataoldnew_index

-- DROP INDEX public.ix_dataoldnew_index;

CREATE INDEX ix_dataoldnew_index
  ON public.dataoldnew
  USING btree
  (index);

谢谢你提前

0 个答案:

没有答案