Feeling lazy, does SQL offer something like select * from table where (a,b) in ((1,2), (2,3)) ? - I know you could perhaps do something like a||b but I'd prefer not to. Anything neat? UPDATE: this syntax I suggested as an example turns out to just work!

Follow

@bert_hubert

In PostgreSQL we could do:

CREATE TABLE t (a int, b int);

INSERT INTO t VALUES (1, 2), (3, 4), (5, 6);

SELECT t.*
FROM t
JOIN (
VALUES (1, 2), (3, 4)
) v(a, b)
ON (t.a = v.a AND t.b = v.b);

a | b
---+---
1 | 2
3 | 4

Another approach would be an array for a and b:

SELECT *
FROM t
WHERE a = ANY(ARRAY[1, 3])
AND b = ANY(ARRAY[2, 4]);

If you really wanted the 2d array, then there are ways to unpack that and join against it.

@intrbiz @bert_hubert In PostgreSQL you can do exactly what Bert asked for:

select * from t
where (a, b) in ((1, 2), (3, 4))

See dbfiddle.uk/m3Oe8AT4

Sign in to participate in the conversation
Mastodon

Time for a cuppa... Earl Grey please!