James
James

Reputation: 11

using squiggle-sql to build dynamic sql with OR clause

I want to build Select fields and Where clause dynamically with OR condition using squiggle-sql api. Please take more than two fields as an example.

Select field1,filed2,filed3,field4,..... 
from t1,t2,t3 
where t1.field1 = t2.field1 and t1.field1 = t3.field1 

where t1.field=? OR t2.field3=? OR t3.field2=?

Please suggest.

Upvotes: 1

Views: 975

Answers (2)

Lukas Eder
Lukas Eder

Reputation: 221165

I have just discovered Squiggle recently. It seems to be very similar to jOOQ (of which I am the developer). In jOOQ, you could write (I'm sure Squiggle offers similar functionality)

List<Field<?>> fields = new ArrayList<Field<?>>();
fields.add(field1);
fields.add(field2);
// ... add more fields here

Condition condition = T1.field.equal(...);
condition = condition.or(T2.field3.equal(...));
condition = condition.or(T3.field2.equal(...));
// ... connect more conditions here

DSL.using(configuration)
   .select(fields)
   .from(t1, t2, t3)
   .where(t1.field1.equal(t2.field1))
   .and(t2.field1.equal(t3.field1))
   .and(condition);

For more information, see http://www.jooq.org

Upvotes: 1

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115630

Two WHERE at the same SELECT will produce an error. Do you mean this?

Select field1,filed2,filed3,field4,..... 
from t1,t2,t3 
where t1.field1 = t2.field1 and t1.field1 = t3.field1 

AND (t1.field=? OR t2.field3=? OR t3.field2=?)

Upvotes: 0

Related Questions