As example we have a table:
CREATE TABLE t1 (
a BYTEA NOT NULL,
r_pointer BIGINT,
s_pointer BIGINT,
data BYTEA,
PRIMARY KEY(a, r_pointer)
) PARTITION BY HASH (a);
In case we I want get last element:
SELECT * FROM t1 WHERE a ='\xaaa' order by r_pointer desc limit 1;
Of course, I can use executemany
for this statement, but this is not very good for performance.
How can I get only the first row found for each element in a given array like {\xaaa,\xbbbb}
. Similar to the following, but this returns all rows:
SELECT * FROM t1
WHERE a = ANY ('{\xaaa,\xbbbb}'::bytea[])
ORDER BY r_pointer DESC;
executemany
is not Postgres terminology. Are you thinking of MySQL? Or something like psycopg? Please also clarify: Postgres version, how many input values (min/max/avg), cardinality oft1
, what to return exactly when no matching row is found for one / all input values. The best course of action depends on these details.