PostgreSQL中的SQL时间戳

2024-09-29 22:31:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图理解PostgreSQL保存timestamp数据类型的原始方式。根据我使用的客户机,我得到两个不同的结果:

1。psql

# SELECT date_incorporated FROM client;

   date_incorporated    
------------------------
 2017-06-14 19:42:15-04

2。recordspython模块

^{pr2}$

由于psql接口和records模块都应该将原始数据返回给我,我不明白为什么这两个模块都返回了它们存储的时间戳的不同格式。在

到目前为止,我看到的两个不同之处是Trecords版本中位于日期和时间之间的中间,以及它在字符串末尾显示时区的不同方式

有人在改变吗?哪一个显示的是真实的数据?在


Tags: 模块fromclientdate客户机postgresql方式时间
1条回答
网友
1楼 · 发布于 2024-09-29 22:31:12

https://www.postgresql.org/docs/current/static/datatype-datetime.html

All timezone-aware dates and times are stored internally in UTC. They are converted to local time in the zone specified by the TimeZone configuration parameter before being displayed to the client.

https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT

The output format of the date/time types can be set to one of the four styles ISO 8601, SQL (Ingres), traditional POSTGRES (Unix date format), or German. The default is the ISO format.

例如:

t=# select now();
              now
               -
 2017-11-29 09:07:31.716276+00
(1 row)

t=# set datestyle to SQL;
SET
t=# select now();
              now
                
 11/29/2017 09:07:52.341416 UTC
(1 row)

所以时间是节省的,而不是返回的方式。至少没有。您可以在一定程度上控制它如何返回给您的客户机。psql不处理时间。但是python确实如此。我相信不是records而是python本身

https://en.wikipedia.org/wiki/ISO_8601

T is the time designator that precedes the time components of the representation.

而且T肯定不是postgres自己添加的(除非您故意用to_char格式化日期)

相关问题 更多 >

    热门问题