Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on the format of datetime #66

Closed
jiamo opened this issue May 23, 2018 · 2 comments
Closed

Question on the format of datetime #66

jiamo opened this issue May 23, 2018 · 2 comments

Comments

@jiamo
Copy link

jiamo commented May 23, 2018

I use wal2json and psycopg2 to got postgresql data change. I have a question on the format of datatime. In psql I have column type timestamp with timezone

In psql console:

postgres=# select create_time from test limit 1;
          create_time
-------------------------------
 2018-05-18 03:06:22.446039+00

In some graph ide like DataGrip (after I click on the column)

create_time
2018-05-18 03:06:22.446039 +00:00

The wal2json return '2018-05-18 03:06:22.446039+00'. But I look at https://docs.python.org/3/library/datetime.html The %z is '+0000' have 4 digit.
Does I got some misunderstanding on the stand?

@eulerto
Copy link
Owner

eulerto commented May 23, 2018

@jiamo wal2json uses the same output as the corresponding data type. Take a look at backend/utils/adt/datetime.c, function EncodeTimezone. If the timezone have its minute part as zero, it is not printed (which means that -03:00 will be printed as -03 and -03:30 will be printed as -03:30 ). AFAIR ISO 8601 supports minutes omission in timezone specification (-07:00 is the same as -07 ).

The output depends on DateStyle parameter (read [1]).

postgres=# show DateStyle;
 DateStyle 
-----------
 ISO, MDY
(1 row)

postgres=# select now();
              now              
-------------------------------
 2018-05-23 02:56:06.535951+00
(1 row)

postgres=# set DateStyle to 'SQL';
SET
postgres=# select now();
              now               
--------------------------------
 05/23/2018 02:56:27.382021 UTC
(1 row)

postgres=# set DateStyle to 'Postgres';
SET
postgres=# select now();
                 now                 
-------------------------------------
 Wed May 23 02:56:37.656014 2018 UTC
(1 row)

[1] https://www.postgresql.org/docs/10/static/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT

@jiamo
Copy link
Author

jiamo commented May 23, 2018

I got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants