1

TIMESTAMP type should be fine (docs)

timestamp [ (p) ] [ without time zone ] 8 bytes both date and time (no time zone) 1 microsecond / 14 digits

Create the table like:

CREATE TABLE IF NOT EXISTS l12(
    timestamp TIMESTAMP(6) NOT NULL,

But what I get is

psycopg2.errors.DatetimeFieldOverflow: date/time field value out of range: "2019-05-23 12:16:50.954276"

When I remove the last three numbers 2019-05-23 12:16:50.954276--> 2019-05-23 12:16:50.954 the insert works.

So is it possible to save a datetime with six decimals precision into one postgresql field?

  • 1
    The fact described above cannot be reproduced. fiddle. I think it is a client issue, not PostgreSQL one. – Akina Aug 15 at 10:36
  • Yes... Just tried it again directly on the DB. So it looks like psycopg2 has some issue – gies0r Aug 15 at 10:42
0

Thanks to Akina, I found the problem. The error has been on client-side, because I used the following in the INSERT function:

INSERT INTO l12 VALUES (TO_TIMESTAMP('2019-05-23 12:16:50.954276', 'YYYY-MM-DD HH24:MI:SS.ms'))

which fails with the mentioned ERROR: date/time field value out of range: "2019-05-23 12:16:50.954276"

Just remove that TO_TIMESTAMP function and be happy or use 'YYYY-MM-DD HH24:MI:SS.msus as the correct formating input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.