Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 47A792E2EBB for ; Thu, 29 Nov 2007 05:21:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 48876-09 for ; Thu, 29 Nov 2007 05:21:33 -0400 (AST) Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by postgresql.org (Postfix) with ESMTP id 61C9A2E0226 for ; Thu, 29 Nov 2007 05:21:32 -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 1IxfaK-0006x9-1J; Thu, 29 Nov 2007 22:21:28 +1300 Message-ID: <474E849F.3050603@opencloud.com> Date: Thu, 29 Nov 2007 22:21:35 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: yoursoft CC: pgsql-jdbc@postgresql.org Subject: Re: PreparedStatement vs. Statement problem References: <474E5E18.4080909@freemail.hu> In-Reply-To: <474E5E18.4080909@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/87 X-Sequence-Number: 17842 yoursoft wrote: > I have a problem: > SELECT * FROM mytable WHERE c1 like 'a' UNION ALL SELECT * FROM mytable > WHERE c2 like 'a' || '%' AND c2 not like 'a' UNION ALL SELECT * FROM > mytable WHERE c2 like '%' || 'a' || '%' AND c2 not like 'a' || '%' AND > c2 not like 'a' LIMIT 101 OFFSET 0 > > Where 'a' is a variable. > When I run this query from Statement. There is no problem. The result is > ordered by: First SELECT, second SELECT third SELECT. > When I run this query from PreparedStatement ('a' values replaced by ?). > The result is ordered by in alphabets.Why? You don't have an ORDER BY so the result ordering is undefined. The planner happens to pick different plans in the two cases which result in different orderings. -O