Assume I have a table records
with the following structure
- id (unique int)
- updated (timestamp)
I have an input_array
with values [[id_1, timestamp_1], [id_4, timestamp_4], ...]
. I'll refer to each element as tuple_1
, tuple_4
, etc.
I'm looking for the most efficient query (in PostgreSQL v11.2+) to select [id_1, id_4, ...]
from records
, but only where tuple_{n}.updated > row{n}.updated
. Assume input_array
may contains thousands of tuples, and records
upwards of a million rows.
I don't even know where to begin with this. Lateral join
comes to mind, as does unnest
, and where in
, but everything I've tried so far fails miserably
Update I'm open to input_array
being in any format (tuples, two separate arrays, whatever), and updated
being an int