[英]Timestamp with timezone in PostgreSQL 9.6
I am currently searching my transaction table using the following query. 我目前正在使用以下查询搜索我的交易表。 The second TO_TIMESTAMP is specified as 2019-08-21..
第二个TO_TIMESTAMP指定为2019-08-21。
SELECT t.* FROM Transaction t WHERE t.datetime >= TO_TIMESTAMP('2019-01-01T07:54:34','YYYY-MM-ddTHH:MI:SS')
AND t.datetime < TO_TIMESTAMP('2019-08-21T14:38:34','YYYY-MM-ddTHH:MI:SS') AND (t.location_1 = 2001 OR t.location_2 = 2001);
It returns me the following result: 它返回以下结果:
When i change the second TO_TIMESTAMP to 2019-08-22.. It returns me the current day's result. 当我将第二个TO_TIMESTAMP更改为2019-08-22时。它将返回当天的结果。 I am not sure why I need to add one more day in order to retrieve the current day's result..
我不确定为什么我需要再增加一天才能检索当天的结果。
The current timezone in the PostgreSQL 9.6 is: PostgreSQL 9.6中的当前时区为:
This is your problem: 这是你的问题:
SELECT TO_TIMESTAMP('2019-08-21T14:38:34','YYYY-MM-ddTHH:MI:SS');
to_timestamp
------------------------
2019-08-21 00:38:34+00
(1 row)
The unescaped T
confuses the parser (the actual result may even be buggy). 未转义的
T
会使解析器感到困惑(实际结果甚至可能是错误的)。
Use the correct format string: 使用正确的格式字符串:
SELECT TO_TIMESTAMP('2019-08-21T14:38:34','YYYY-MM-DD"T"HH24:MI:SS');
to_timestamp
------------------------
2019-08-21 14:38:34+00
(1 row)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.