Why is Positco returning an incorrect timestamptz than what is being passed in with psycopg2

30 views Asked by At

I have a script that is passing in a timestamp into a Postgres database. I am viewing the DB with Postico.

I am attempting to pass in a UTC value, by which I mean I want the DB to store all values at +00 timezone. I am using a timestamptz entry in the DB.

On the line prior to writing to the DB, I am printing the value that is being written. The Python console returns:

2018-11-21 10:03:06+00:00

but when I view it on Postico I get:

2018-11-21 11:03:06+01.

Why is Positco returning something different than what is being written? The code is as follows:

import time

import psycopg2

import datetime


def write_to_db(entry):
    conn = psycopg2.connect("dbname=testing user=tester")

    cur = conn.cursor()
    print(entry)
    cur.execute("INSERT INTO test (ts) VALUES (%s)", (entry, ))

    conn.commit()
    cur.close()
    conn.close()

def main():
    dt = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).replace(microsecond = 0)
    write_to_db(dt)


if __name__ == '__main__':
    main()

Reading from the database returns the following:

(datetime.datetime(2018, 11, 21, 11, 3, 6, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)),)

So maybe it is an issue with psycopg2 writing to the database?

0

There are 0 answers