我的表格如下:
广告
inventory | creationDate
{} | 2017-04-27 14:15:15.25+02
{} | 2017-04-27 13:03:02.205+02
{} | 2017-04-27 13:03:01.766+02
{} | 2017-04-27 13:02:19.8+02
{} | 2017-04-27 12:35:52.12+02
查询:
SELECT * FROM "Inventory"
WHERE "registerTillInventoryId" = 1
AND "creationDate" <= '2017-04-27 12:02:38.000 +00:00'
ORDER BY "creationDate" DESC;
结果:
inventory | creationDate
{} | 2017-04-27 13:03:02.205+02
{} | 2017-04-27 13:03:01.766+02
{} | 2017-04-27 13:02:19.8+02
{} | 2017-04-27 12:35:52.12+02
我的问题是我从
获取数据的原因13:03:02.205+02 and 13:03:01.766+02
我的查询结果应为
inventory | creationDate
{} | 2017-04-27 13:02:19.8+02
{} | 2017-04-27 12:35:52.12+02
答案 0 :(得分:0)
'2017-04-27 12:02:38.000 +00:00'
是'2017-04-27 14:02:38.000 +00:02'
,
所以它返回'2017-04-27 14:15:15.25+02'
以外的所有值,因为它是唯一不符合"creationDate" <= '2017-04-27 12:02:38.000 +00:00'
哪个是对的。例如:
t=# with a as (select '2017-04-27 12:02:38.000 +00:00' at time zone 'utc' ts)
select ts, ts at time zone 'gmt+2' from a;
ts | timezone
---------------------+------------------------
2017-04-27 12:02:38 | 2017-04-27 14:02:38+00
(1 row)
Time: 0.480 ms
为什么不只是"creationDate" <= '2017-04-27 12:02:38.000'
以避免混合tz?..
答案 1 :(得分:0)
好的,谢谢你的帮助。我在Vao Tsun评论的帮助下解决了这个问题。
我没有描述的是我试图从12:02 +00:00获得13:02
我真的不需要时区。 所以,如果我查询
creationDate < '2017-04-27 13:02:38.000'
直接。没有时区,我得到了正确的结果。
{} | 2017-04-27 13:02:19.8+02
{} | 2017-04-27 12:35:52.12+02
...