Suppose I have the table foo
. I want to filter the rows of this table using different conditions (cond_1
, cond_2
, …, cond_n
– the order is important) combined in a disjunction, i.e.:
SELECT * FROM foo WHERE cond_1 OR cond_2 OR ... OR cond_n;
- Is it possible (in PostgreSQL 13) to distinguish for each row which condition
cond_i
was used to select it? Since I stated that the order is important the question may be reformulated as – I want to know the firstcond_i
that selected the row, for each row.
Now consider that I have in foo
a column for this purpose, e.g. selected_by
.
- Is it possible to distinguish for each row which condition
cond_i
was used to select it and store it inselected_by
? (the same as 1st question but for an UPDATE statement)
Two things are important: the order of conditions (as it was highlighted earlier); performance (i.e. table foo
may have many rows, the number of conditions is small, up to 5-10).