Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id CD8842E2EF4 for ; Thu, 29 Nov 2007 06:27:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 58902-01 for ; Thu, 29 Nov 2007 06:27:07 -0400 (AST) Received: from skuns.kiev.zoral.com.ua (ll-226.216.82.212.sovam.net.ua [212.82.216.226]) by postgresql.org (Postfix) with ESMTP id 894292E007F for ; Thu, 29 Nov 2007 06:27:10 -0400 (AST) Received: from [10.1.1.57] (tivv.kiev.zoral.com.ua [10.1.1.57]) (authenticated bits=0) by skuns.kiev.zoral.com.ua (8.14.1/8.14.1) with ESMTP id lATAQcbQ018127 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Nov 2007 12:26:38 +0200 (EET) (envelope-from tivvpgsqljdbc@gtech-ua.com) Message-ID: <474E9208.8040605@gtech-ua.com> Date: Thu, 29 Nov 2007 12:18:48 +0200 From: tivvpgsqljdbc@gtech-ua.com User-Agent: Thunderbird 2.0.0.9 (X11/20071114) MIME-Version: 1.0 To: Oliver Jowett CC: yoursoft , Postgres JDBC Subject: Re: PreparedStatement vs. Statement problem References: <474E5E18.4080909@freemail.hu> <474E849F.3050603@opencloud.com> <474E87E9.3050609@freemail.hu> <474E88DB.7030306@opencloud.com> In-Reply-To: <474E88DB.7030306@opencloud.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV version 0.91.2, clamav-milter version 0.91.2 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.697 tagged_above=0 required=5 tests=BAYES_00=-2.599, FROM_LOCAL_NOVOWEL=3.196, RDNS_DYNAMIC=0.1 X-Spam-Level: X-Archive-Number: 200711/92 X-Sequence-Number: 17847 Oliver Jowett wrote: > yoursoft wrote: >> Ok, the planner uses different way. I think the planner use the UNION >> in PreparedStatement and not the UNION ALL? >> How to rewrite the SQL to use the UNION ALL in preparedstatement? > > You need an ORDER BY or the order is undefined and unpredictable. See > http://www.postgresql.org/docs/8.2/static/queries-order.html > > There's no simple way to say "give me rows from this table first" > other than running a query on each table separately. Actually the simple way is select c1,c2,c3,...,cn from (select 1, table1.* from table1 union all select 2, table2.* from table2 union all ...) a(ordercolumn, c1, c2, c3, .., cn) order by 1