-2

Is it possible to add condition within the in clause of postgresql

for example

select ... where (t1.subject,t2.weight) in ((1,2),(2,3))

I want to check whether subject is 1 but weight can be >= 2 not just 2 and so on. So that condition would logically look somewhat like

select ... where (t1.subject,t2.weight) in ((1,>2),(2,>3))
  • Meaningless code does not communicate to others what you wish it meant. Also "like" & "somewhat" do not explain "is". And "logically" doesn't mean anything in particular. Please: Use enough words, sentences & references to parts of examples to clearly & fully say what you mean. Please in code questions give a [mre]. [ask] [Help] Show what you are able to do. Research before considering asking & reflect research in a question. [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/3404097) – philipxy Oct 13 '22 at 18:28

2 Answers2

1

No, this is not possible. You need to write

…
WHERE t1.subject = 1 AND t2.weight > 2
   OR t1.subject = 2 AND t2.weight > 3;
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

You can select value of object using subquery. Simple just select query subject which are having weight greater than >=2.

select ... where (t1.subject,t2.weight) in (select subject FROM ... where weight >=2 ,select subject FROM ... where weight >=3 );