Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 48FC32E2EEA for ; Thu, 29 Nov 2007 05:39:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 71676-09 for ; Thu, 29 Nov 2007 05:39:30 -0400 (AST) Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by postgresql.org (Postfix) with ESMTP id ADF8E2E2ED5 for ; Thu, 29 Nov 2007 05:39:33 -0400 (AST) Received: from 222-154-183-126.jetstream.xtra.co.nz ([222.154.183.126] helo=[192.168.1.2]) by tremor.opencloud.co.nz with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1Ixfro-00072x-02; Thu, 29 Nov 2007 22:39:32 +1300 Message-ID: <474E88DB.7030306@opencloud.com> Date: Thu, 29 Nov 2007 22:39:39 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: yoursoft CC: Postgres JDBC Subject: Re: PreparedStatement vs. Statement problem References: <474E5E18.4080909@freemail.hu> <474E849F.3050603@opencloud.com> <474E87E9.3050609@freemail.hu> In-Reply-To: <474E87E9.3050609@freemail.hu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/88 X-Sequence-Number: 17843 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. -O