TheShahin
TheShahin

Reputation: 153

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');

Upvotes: 0

Views: 2375

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220952

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');

Upvotes: 1

Related Questions