pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ludwig Isaac Lim <ludz_lim@yahoo.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Strange behavior between timestamp and date comparison
Date: Sat, 23 Jul 2022 10:04:24 +0000 (UTC)
Message-ID: <1485906141.916850.1658570664512@mail.yahoo.com> (raw)
References: <1485906141.916850.1658570664512.ref@mail.yahoo.com>

Hello:

Below is a sample case that exhibits a behavior that I can't explain:

-- create the table
create table ts (t timestamp without time zone);

-- populate
insert into ts(t) values ('2022-07-16 00:22:06.974000');
insert into ts(t) values ('2022-07-16 00:22:06.974000');
insert into ts(t) values ('2022-07-16 00:22:06.974000');



-- This one return expected results
select * from ts where t::date between '2022-07-16'::Date - make_interval(days => 30) and '2022-07-16'::Date;
            t
-------------------------
 2022-07-16 00:22:06.974
 2022-07-16 00:22:06.974
 2022-07-16 00:22:06.974
(3 rows)


-- This one doesn't return anything (unexpected)
 select * from ts where t between '2022-07-16'::Date - make_interval(days => 30) and '2022-07-16'::Date;
 t
---
(0 rows)

-- version
select version();
                                                 version
---------------------------------------------------------------------------------------------------------
 PostgreSQL 14.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-15), 64-bit
(1 row)



Regards,
Ludwig Lim






view thread (3+ messages)  latest in thread

Message-ID: <1485906141.916850.1658570664512@mail.yahoo.com>
Permalink:  ../1485906141.916850.1658570664512@mail.yahoo.com/
Also on:    postgresql.org/message-id/1485906141.916850.1658570664512@mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ludz_lim@yahoo.com
  Subject: Re: Strange behavior between timestamp and date comparison
  In-Reply-To: <1485906141.916850.1658570664512@mail.yahoo.com>
  References: <1485906141.916850.1658570664512.ref@mail.yahoo.com> <1485906141.916850.1658570664512@mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox