Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cAJ7z-0006cx-34 for pgsql-sql@arkaria.postgresql.org; Fri, 25 Nov 2016 16:13:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cAJ7y-00032Z-MG for pgsql-sql@arkaria.postgresql.org; Fri, 25 Nov 2016 16:13:30 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c9qF6-0000bN-0r for pgsql-sql@postgresql.org; Thu, 24 Nov 2016 09:22:56 +0000 Received: from zimbra.isdd.sk ([91.233.248.205]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c9qF3-0004RH-He for pgsql-sql@postgresql.org; Thu, 24 Nov 2016 09:22:54 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.isdd.sk (Postfix) with ESMTP id 63F0018818F8; Thu, 24 Nov 2016 10:22:51 +0100 (CET) Received: from zimbra.isdd.sk ([127.0.0.1]) by localhost (zimbra.isdd.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id e1kJFWaGRy82; Thu, 24 Nov 2016 10:22:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.isdd.sk (Postfix) with ESMTP id 2A2081881924; Thu, 24 Nov 2016 10:22:50 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.isdd.sk Received: from zimbra.isdd.sk ([127.0.0.1]) by localhost (zimbra.isdd.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id J9TGcrDc8kJn; Thu, 24 Nov 2016 10:22:50 +0100 (CET) Received: from zimbra.isdd.sk (zimbra.isdd.sk [91.233.248.205]) by zimbra.isdd.sk (Postfix) with ESMTP id 09DCB18818F8; Thu, 24 Nov 2016 10:22:50 +0100 (CET) Date: Thu, 24 Nov 2016 10:22:49 +0100 (CET) From: Jan Ostrochovsky To: Metatrader EA Cc: pgsql-sql Message-ID: <1685623271.4216209.1479979369717.JavaMail.zimbra@mobiletech.sk> In-Reply-To: References: Subject: Re: Dynamic queries for Partitions MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4216208_921123488.1479979369716" X-Mailer: Zimbra 8.6.0_GA_1153 (ZimbraWebClient - GC54 (Win)/8.6.0_GA_1153) Thread-Topic: Dynamic queries for Partitions Thread-Index: GIViy8k10R5gb0ObnAyrG2ltTnv9uw== X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org ------=_Part_4216208_921123488.1479979369716 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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" > To: "pgsql-sql" > 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 ------=_Part_4216208_921123488.1479979369716 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hello Bill,

i= f I understand correctly, you need to have constraint exclusion turned on a= nd 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 ste= ps, but just one - one SELECT from master table fits all. Details are in th= e PostgreSQL documentation (Partitioning).

Jano


From: "Metatrader EA" <metatraderea@gmail.com>
<= b>To: "pgsql-sql" <pgsql-sql@postgresql.org>
Sent: Wedn= esday, 23 November, 2016 15:54:03
Subject: [SQL] Dynamic queries = for Partitions
<= blockquote style=3D"border-left:2px solid #1010FF;margin-left:5px;padding-l= eft:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:non= e;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
=
Hi,

When I run one query on one partitioned table. <= br>
Select * from customer where opendate =3D (date_trunc('mo= nth', current_date)+'11 days'::interval)::date ;

This que= ry will do that postgres will check all my partitions.

Ho= w can I do ?

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

S= tep 2 :: Then run code from step1.

Any advice?

//Bill

------=_Part_4216208_921123488.1479979369716--