Derek_P
Derek_P

Reputation: 666

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"

Upvotes: 2

Views: 692

Answers (1)

klin
klin

Reputation: 121604

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.

Upvotes: 3

Related Questions