简体   繁体   中英

Passing a List of Conditions to a WHERE-clause in JOOQ

My question is very simple, really, I just want to know what boolean operator is used in the generated SQL when passing a List of Conditions to a WHERE-clause using JOOQ.

For example:

List<Condition> conditions = new ArrayList<>();
conditions.add(MY_TABLE.MY_COLUMN1.equal("Foo").and(MY_TABLE.MY_COLUMN2.equal("Far"));
conditions.add(MY_TABLE.MY_COLUMN1.equal("Boo").and(MY_TABLE.MY_COLUMN2.equal("Bar"));
DSL.selectFrom(MY_TABLE).where(conditions).fetch();

Is the resulting SQL this:

SELECT * FROM MY_TABLE WHERE (MY_COLUMN1='Foo' AND MY_COLUMN2='Far') OR (MY_COLUMN1='Boo' AND MY_COLUMN2='BAR');

or this:

SELECT * FROM MY_TABLE WHERE (MY_COLUMN1='Foo' AND MY_COLUMN2='Far') AND (MY_COLUMN1='Boo' AND MY_COLUMN2='BAR');

The conditions are AND -connected. While the Javadoc on SelectWhereStep.where(Condition...) doesn't mention this ( which should be fixed ), the underlying implementation is that of SelectQuery.addConditions(Condition...) , which specifies usage of Operator.AND .

So the resulting query will be your second example:

SELECT * FROM MY_TABLE 
WHERE (MY_COLUMN1='Foo' AND MY_COLUMN2='Far') 
  AND (MY_COLUMN1='Boo' AND MY_COLUMN2='BAR');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM