Emulate DISTINCT ON in Oracle

6 views
Skip to first unread message

Mark L.

unread,
Apr 25, 2018, 4:28:33 AM4/25/18
to jOOQ User Group
Hi,

I tried:
        Result<Record2<BigInteger, BigInteger>> record = create
           
.select(
                TEST
.ID, TEST.SESSION_ID
               
).distinctOn(TEST.SESSION_ID).from(TEST)
           
.orderBy(TEST.SESSION_ID, TEST.ID)
           
.fetch();



which works perfectly on POSTGRES. But since Oracle isn't supporting that feature there will be an error.

Are there any plans for adding an emulation as stated in 2012:
https://stackoverflow.com/questions/10515391/oracle-equivalent-of-postgres-distinct-on/10515397#10515397

Greets, Mark


Lukas Eder

unread,
Apr 26, 2018, 7:28:20 AM4/26/18
to jooq...@googlegroups.com
Hi Mark,

Thank you very much for your message. Indeed, DISTINCT ON is quite a handy PostgreSQL extension to the SQL standard. It's definitely possible to emulate it in trivial cases, but there are also a few non-trivial ones when you mix unions / order by / window functions, which must still produce the correct results.

There's a pending feature request on the roadmap:

But given the non-triviality of this emulation (both in general, as well as in jOOQ's internals), I cannot make any promises yet as to when this can be supported.

In order to get vendor-agnostic functionality here, I suspect you'll need to emulate the clause manually.

Hope this helps,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages