values table expression generating parameters in the row and need customization for database which doesn't support column aliases

12 views
Skip to first unread message

Mohan

unread,
Nov 28, 2017, 1:25:17 AM11/28/17
to jOOQ User Group
Hi,

I need help in the below to code to generate right select from values with the values I am passing instead of parameters.

Below is the sample code i am trying to execute.

DSLContext dsl;
Settings settings = new Settings()
 
.withRenderNameStyle(RenderNameStyle.AS_IS).withRenderFormatted(true);
dsl
= DSL.using(SQLDialect.DEFAULT, settings);
String sql = dsl.select().from(DSL.values(DSL.row(43,1234,"value1"),DSL.row(43,1235,"value2"))).getSQL();
System.out.println(sql);


Output is generating as below. 

select 
  v.c1, 
  v.c2, 
  v.c3
from (values
  (?, ?, ?),
  (?, ?, ?)
) v(c1, c2, c3)

So I need help in fixing the above to generate as below because my database doesn't support column aliases

select 
    column1,
    column2,
    column3
from values (43,1234,'value1'),(43,1235,'value2')

Is there any way I can achieve the above format?

Regards,
Mohan


Lukas Eder

unread,
Nov 28, 2017, 5:30:17 AM11/28/17
to jooq...@googlegroups.com
Hi Mohan,

You chose the SQLDialect.DEFAULT dialect, which is a dialect that can be used for documentation purposes (e.g. when calling toString(), etc.), and usually generates SQL standard compliant SQL, if possible, although there is no such guarantee.

You should replace that dialect by the dialect of your target database, and then jOOQ will either generate the derived column list as you got it already"v(c1, c2, c3)", or it will emulate derived column lists using UNION ALL. This is documented here:

I 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.

Mohan

unread,
Nov 28, 2017, 8:39:58 AM11/28/17
to jOOQ User Group
Hi,

Thanks for the reply. My target database is Snowflake. So which dialect I should use. Also I am using jooq as sql query generator.

Lukas Eder

unread,
Nov 28, 2017, 8:46:11 AM11/28/17
to jooq...@googlegroups.com
Hi Mohan,

Well, that's a good question :) We don't officially support Snowflake, so it may well be that this particular feature cannot be properly emulated. You could use a dialect like Oracle for this particular query, but then other queries might stop working...

I suggest you don't use the VALUES() clause, but manually write your own SELECT .. UNION ALL SELECT .. UNION ALL SELECT .. derived table.

I hope this helps,
Lukas
2017-11-28 14:39 GMT+01:00 Mohan <ramubt...@gmail.com>:
Hi,

Thanks for the reply. My target database is Snowflake. So which dialect I should use. Also I am using jooq as sql query generator.
Reply all
Reply to author
Forward
0 new messages