Обсуждение: Dynamic queries for Partitions

Поиск
Список
Период
Сортировка

Dynamic queries for Partitions

От
Metatrader EA
Дата:
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

Re: Dynamic queries for Partitions

От
Jan Ostrochovsky
Дата:
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