Skip to content

Instantly share code, notes, and snippets.

@timowest
Last active March 16, 2023 23:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timowest/5098112 to your computer and use it in GitHub Desktop.
Save timowest/5098112 to your computer and use it in GitHub Desktop.
Querydsl and/or examples
#1
e1.or(e2).and(e3))
creates at first an 'or' operation based on e1 and e2 and uses this 'or' operation
in a top level 'and' operation with e3 as the second operand.
Since 'and' has higher precedence than 'or' it is serialized as
(e1 or e2) and e3
#2
e1.or(e2).and(e3.or(e4)))
'and' is the top level operation and e1.or(e2) and e3.or(e4) are the lower level operations
It is serialized as
(e1 or e2) and (e3 or e4)
#3
e1.and(e2).or(e3.and(a4))
`or`is the top level operation and e1.and(e2) and e3.and(e4) are the lower level operations
It is serialized as
e1 and e2 or e3 and e4
@t2006036
Copy link

@iheb719
Thank you for teaching me operator priority

@Alan666156
Copy link

How can I create?
((e1 or e2) and e3) or (e4 and e5 and e6)

sql examples:
and (
(
(t3.id is null or t3.is_deleted = 1)
and t2.settle_cycle_id is NULL
and t1.settle_date BETWEEN '2022-04-01' and '2022-04-22'
)
or
(
t3.id is not null
and t3.is_deleted = 0
and t1.settle_date BETWEEN '2022-04-01' and '2022-04-22'
)
)

@SeongEon-Jo
Copy link

As I understand, if I want to get e1 and e2 and ((e3 and e4) or e5), it will be e1.and(e2).and(e3.and(e4).or(e5)).

But actually, I got e1 and e2 and (e3 and e4 or e5).

What is the matter? Please help me...

@virgo47
Copy link

virgo47 commented Mar 15, 2023

@SeongEon-Jo That's OK. AND has higher priority than OR, so "e1 and e2 and (e3 and e4 or e5)" means that "e3 and e4" will be evaluated first, then "... or e5" and then it's all AND-ed. Just the redundant parentheses are removed. It will work the same.

@SeongEon-Jo
Copy link

@virgo47 Oh, I got it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment