Re: PreparedStatement vs. Statement problem - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: PreparedStatement vs. Statement problem
Date
Msg-id 474E849F.3050603@opencloud.com
Whole thread Raw
In response to PreparedStatement vs. Statement problem  (yoursoft <yoursoft@freemail.hu>)
List pgsql-jdbc
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

pgsql-jdbc by date:

Previous
From: yoursoft
Date:
Subject: PreparedStatement vs. Statement problem
Next
From: Oliver Jowett
Date:
Subject: Re: PreparedStatement vs. Statement problem