pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alan Jackson <ajax@tvsquared.com>
To: pgsql-bugs@lists.postgresql.org
Subject: inconsistent results querying table partitioned by date
Date: Thu, 9 May 2019 17:45:55 +0100
Message-ID: <FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com> (raw)

Hi

Im having a problem with querying a table partitioned by date.

Depending on the sequence of operations on a date parameter used in a where clause, I either get the expected results, or no results.

This suggests a bug in the handling of date parameters and partition range handling.

I’ve replicated this down to a single sequence of create table, insert data, query.

This issue occurs for me on postgresql 11.2 on a mac, installed via brew.

In this case the table is partitioned by an id and then by the date, if it is partitioned by only the date everything works as expected.

However, I am attempting to add partitioning to a fairly large sofware-as-a-service platform, so making changes to the table definitions or global code changes is not really practical.

The sql in question is below.

I hope there is something simple I can change in the partition definitions to work around this.

Many Thanks,
Alan Jackson
Data Architect 
TVSquared


--SQL STARTS HERE

--drop table dataid;
CREATE TABLE dataid
(
id integer not null,
datadatetime timestamp without time zone NOT NULL,
CONSTRAINT dataid_pkey PRIMARY KEY (id, datadatetime)
) PARTITION BY RANGE (id, datadatetime) 
;

CREATE TABLE dataid_201902 PARTITION OF dataid FOR VALUES FROM (1, '2019-02-01 00:00:00') TO (1, '2019-03-01 00:00:00');

CREATE TABLE dataid_default PARTITION OF dataid DEFAULT;

insert into dataid values (1,'2019-02-24T00:00:00');

--- returns 1 row as expected
select * from dataid where id=1 and datadatetime <  (('2019-02-26T00:00:00'::timestamp::timestamp at time zone 'America/New_York' ) at time zone 'UTC' + '2 days'::interval);

--- returns no rows
select * from dataid where id=1 and datadatetime <  (('2019-02-26T00:00:00'::timestamp::timestamp at time zone 'America/New_York' + '2 days'::interval) at time zone 'UTC');

-- both date expressions evaluate to the same date.
select 
(('2019-02-26T00:00:00'::timestamp::timestamp at time zone 'America/New_York' ) at time zone 'UTC' + '2 days'::interval) as workingdate,
(('2019-02-26T00:00:00'::timestamp::timestamp at time zone 'America/New_York' + '2 days'::interval) at time zone 'UTC') as notworkingdate;

--SQL ENDS HERE





-- 
TV Squared Limited is a company registered in Scotland.  Registered number: 
SC421072.  Registered office: CodeBase, Argyle House, 3 Lady Lawson Street, 
Edinburgh, EH3 9DR. 
 
TV Squared Inc (File No. 5600204) is an Incorporated 
company registered in Delaware. Principal office: 1412 Broadway, 22 Fl, New 
York, New York, 10018

TV Squared GmbH is a company registered in Munich. 
Registered number: HRB 236077. Registered office: Oskar-von-Miller-Ring 20, 
c/o wework, 80333 Munchen

This message is private and confidential.  If 
you have received this message in error, please notify us and remove it 
from your system.





view thread (41+ messages)  latest in thread

Message-ID: <FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com>
Permalink:  ../FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com/
Also on:    postgresql.org/message-id/FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.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-bugs@postgresql.org
  Cc: ajax@tvsquared.com
  Subject: Re: inconsistent results querying table partitioned by date
  In-Reply-To: <FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com>
  References: <FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.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