JetBrains / JetBrains/Exposed

Adding distinct on to PostgreSQL

Open
#500 13 comments 14 reactions 0 assignees View on GitHub
enhancement postgresql
Dominant language
Kotlin
Stars
9.3k
Forks
798
Avg merge
4d 2h
Merged PRs (30d)
26

Description

How do I add `DISTINCT ON (columns)` to SELECT clause?
I want to make this query:
`SELECT DISTINCT ON (testdummies.id) testdummies.id, testdummies.integer_array, testdummies.name FROM testdummies LEFT JOIN testdummies t0 ON (t0.id = ANY(testdummies.test_dummies) AND t0.name IN ('test2', 'test3') ) WHERE ((testdummies.private = false) OR (testdummies.private IS NULL)) AND t0.name IN ('test2', 'test3') LIMIT 10`

I have looked at the prepareSQL function :
https://github.com/JetBrains/Exposed/blob/master/src/main/kotlin/org/jetbrains/exposed/sql/Query.kt#L159-L208

It doesn't look like I can supply a list of distinct columns. Is there another method that can do this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.