Hi Thomas,

This brings a further question:

It looks like H2 runs twice the same query when it includes an OR in the 
where clause. For example:


select address from PERSONS where name='John' OR name ='Peter'

they work well separately:

=========================

select address from PERSONS where name='John';

*address1*

=========================

select address from PERSONS where name='Peter';

*address2 *

=========================

however combining the above queries with an OR  produces duplicate (and 
unexpected results):

=========================
select address from PERSONS where name='John' OR name ='Peter' 

*address1*
*address2*
*address1*
*address2*
=========================

This is surely because a my misunderstanding about H2 internals.

In my pluggable table I read the condition (name='John' OR name'Peter') and 
collect all of them, so I know I've to add results for John and Peter only, 
then  I add *address1 *and *address2 *into the SimpleResulset.

However, the same code is called again, so it adds the duplicate results:

So I guess the pluggable table is invoked by H2  twice, once for John and 
once for Peter. A sort of UNION:


select address from PERSONS where name='John' OR name ='Peter'

seems to be equivalent to:

select address from PERSONS where name='John' 
UNION
select address from PERSONS where name ='Peter'

How could I identify the conditions applied in each stage:

First, name='John' only and later the same for the next condition 
name='Peter'.

Thanks,
Pablo.



On Saturday, April 11, 2015 at 5:08:19 PM UTC+2, Pablo Beltran wrote:
>
> Hi,
>
> Given a SQL quer... how to get the where clause? 
>
> ...
> String sql = "select * from T where col1=value1 and col2=value2 or 
> col3=value3";
> Parser parser = new Parser(session);
> Select select = (Select) parser.prepare(sql);
>
> String where = ...
>
> //How to get the where clause? "col1=value1 and col2=value2 or col3=value3"
>
> Thanks!
> Pablo.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to