jOOQ / jOOQ

jOOQ is the best way to write SQL in Java
https://www.jooq.org
Other
6.17k stars 1.21k forks source link

Add support for PostgreSQL CROSSTAB() functions #3190

Open lukaseder opened 10 years ago

lukaseder commented 10 years ago

PostgreSQL has a special set of functions to produce PIVOT tables. These functions are called crosstab() and similar, as can be seen here: http://www.postgresql.org/docs/9.3/static/tablefunc.html

It would be interesting to support those functions as well in jOOQ, specifically because jOOQ already supports derived column lists for aliasing such pivot tables.


See also: https://groups.google.com/forum/#!topic/jooq-user/e5F7vWrnLdY

joe-thurbon commented 9 years ago

Just out of interest, I have a utility function that I make extensive use of that takes two Select<?> objects, and constructs a call to crosstab. It's fit for my purposes, but I'm sure that it could be generalised.

If it's of any use to you, I can give it to you.

lukaseder commented 9 years ago

Thank you very much for your offer. It would certainly be very interesting to learn from it - and possibly to merge it into the jOOQ codebase. I'm mostly curious how you implemented the rendering of the SQL statement within a string. Did you just inline the SQL and escaped apostrophes?

joe-thurbon commented 9 years ago

On 25 Aug 2015, at 4:24 pm, Lukas Eder notifications@github.com wrote:

Thank you very much for your offer. It would certainly be very interesting to learn from it - and possibly to merge it into the jOOQ codebase. I'm mostly curious how you implemented the rendering of the SQL statement within a string. Did you just inline the SQL and escaped apostrophes?

That’s exactly what I did.

How would you like the code. Is email O.K?

Cheers, Joe

lukaseder commented 9 years ago

Perfect. Any way would be fine. I think that other users might be interested too, though. So perhaps the user group would be a good place to show the code...? https://groups.google.com/d/forum/jooq-user

lukaseder commented 9 years ago

For future reference, an example was posted here: https://groups.google.com/d/msg/jooq-user/e5F7vWrnLdY/iqMzRIsGFQAJ