agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
Dynamic queries for Partitions
2+ messages / 2 participants
[nested] [flat]

* Dynamic queries for Partitions
@ 2016-11-23 14:54  Metatrader EA <metatraderea@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Metatrader EA @ 2016-11-23 14:54 UTC (permalink / raw)
  To: pgsql-sql

Hi,

When I run one query on one partitioned table.

Select * from customer where opendate = (date_trunc('month',
current_date)+'11 days'::interval)::date ;

This query will do that postgres will check all my partitions.

How can I do ?

Step 1 generate one sql that will be like "Select * from customer where
opendate = '2016-11-01' ;

Step 2 :: Then run code from step1.

Any advice?

//Bill

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Dynamic queries for Partitions
@ 2016-11-24 09:22  Jan Ostrochovsky <jan.ostrochovsky@mobiletech.sk>
  parent: Metatrader EA <metatraderea@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Jan Ostrochovsky @ 2016-11-24 09:22 UTC (permalink / raw)
  To: Metatrader EA <metatraderea@gmail.com>; +Cc: pgsql-sql

Hello Bill, 

if I understand correctly, you need to have constraint exclusion turned on and be careful about types - types in WHERE condition should be the same as those with CHECK constraint in partitioned table. Then you won't need 2 steps, but just one - one SELECT from master table fits all. Details are in the PostgreSQL documentation (Partitioning). 

Jano 

> From: "Metatrader EA" <metatraderea@gmail.com>
> To: "pgsql-sql" <pgsql-sql@postgresql.org>
> Sent: Wednesday, 23 November, 2016 15:54:03
> Subject: [SQL] Dynamic queries for Partitions

> Hi,

> When I run one query on one partitioned table.

> Select * from customer where opendate = (date_trunc('month', current_date)+'11
> days'::interval)::date ;

> This query will do that postgres will check all my partitions.

> How can I do ?

> Step 1 generate one sql that will be like "Select * from customer where opendate
> = '2016-11-01' ;

> Step 2 :: Then run code from step1.

> Any advice?

> //Bill

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-11-24 09:22 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-11-23 14:54 Dynamic queries for Partitions Metatrader EA <metatraderea@gmail.com>
2016-11-24 09:22 ` Jan Ostrochovsky <jan.ostrochovsky@mobiletech.sk>

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