简体   繁体   中英

Postgres timestamp not accepting 2017-01-01T23:00:00-00:00

Working in Jupyter with Python3 and psycopg2 to load csv into psql. First two columns are an ISO format I'm not too familiar with. Is there a simple data type that will accept:

2017-01-01T23:00:00-00:00 

I've tried date, timestamp, timestamp w/o timezone, timestamp w/timezone. Do I need to pre-process in order to convert timestamp to friendlier format?

I thought I could do something like -

cur.execute("""
CREATE TABLE test(
id integer PRIMARY KEY,
intervalbegin_gmt timestamp,
intervalend_gmt timestamp, ...

Getting error -

DataError: invalid input syntax for integer: "2017-01-01T23:00:00-00:00"

The string is a proper timestamp input literal:

select '2017-01-01T23:00:00-00:00'::timestamp

      timestamp      
---------------------
 2017-01-01 23:00:00
(1 row)

The problem is that you are trying to import the column into the integer column id .

First two columns are an ISO format ...

so the table should look like this:

CREATE TABLE test(
    intervalbegin_gmt timestamp,
    intervalend_gmt timestamp, 
    ...

You can add the primary key, if you need it, after copying the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM