-
-
Notifications
You must be signed in to change notification settings - Fork 155
Open
Description
We would like to be able to express Postgres' SELECT DISTINCT ON construct in the ktorm DSL.
Example use-case is below (fiddle):
CREATE TABLE users (id VARCHAR, version BIGINT, data VARCHAR);
INSERT INTO users (id, version, data) VALUES
('id-1', 1, 'foo'),
('id-1', 2, 'bar'),
('id-2', 1, 'alpha'),
('id-2', 2, 'beta'),
('id-2', 3, 'gamma');
SELECT DISTINCT ON (id) id, data FROM users ORDER BY id, version DESC;Results should be the latest for each user, i.e.,
id-1,bar
id-2,gamma
Currently we are doing two round trips to first fetch the set of latest versions, then fetch only those versions. Subquery support would also allow a single trip.
LeahHirst, uga-rosa, DavidMazarro and troyunverdruss
Metadata
Metadata
Assignees
Labels
No labels