使用Postgres

时间:2018-04-01 19:52:03

标签: sql postgresql

我正在尝试使用以下SQL

过滤记录到某一点
select
 orders.total_due,
 orders.created_at
from orders
where orders.last_modified > '2018-03-29T17:44:15.371070+00:00'
order by orders.id;

请注意,我的运算符大于。所以我希望记录比上面的时间戳更新。但是,返回的结果很奇怪:

-[ RECORD 1 ]-----------------------------
total_due  | 100.0
created_at | 2018-03-29 17:44:15.371069+00

奇怪,因为此记录只能由等于或小于运算符匹配(返回的记录与过滤器使用的记录相同)。

更改过滤器时间戳会显示更有趣的内容。将过滤时间戳增加到将来的日期时间(最多约5分钟)仍然允许返回记录。

 --  20 seconds after record
 #  select
     orders.total_due,
     orders.created_at
    from orders
    where orders.last_modified > '2018-03-29T17:44:35.371070+00:00'
    order by orders.id;
-[ RECORD 1 ]-----------------------------
total_due  | 100.0
created_at | 2018-03-29 17:44:15.371069+00

 --  300 seconds after record
 #  select
     orders.total_due,
     orders.created_at
    from orders
    where orders.last_modified > '2018-03-29T17:49:35.371070+00:00'
    order by orders.id;
-[ RECORD 1 ]-----------------------------
total_due  | 100.0
created_at | 2018-03-29 17:44:15.371069+00

 --  15 minutes after record
 #  select
     orders.total_due,
     orders.created_at
    from orders
    where orders.last_modified > '2018-03-29T17:59:35.371070+00:00'
    order by orders.id;
(0 rows)

数据库版本:postgres 9.6

$ dpkg -l |grep postg |grep 9.6
ii  postgresql                                9.6+181+deb9u1                              all          object-relational SQL database (supported version)
ii  postgresql-9.6                            9.6.6-0+deb9u1                              amd64        object-relational SQL database, version 9.6 server
ii  postgresql-client-9.6                     9.6.6-0+deb9u1                              amd64        front-end programs for PostgreSQL 9.6
ii  postgresql-contrib-9.6                    9.6.6-0+deb9u1                              amd64        additional facilities for PostgreSQL

我做错了什么?

0 个答案:

没有答案