Hello,

There's a subtle difference between

- DSL.field()
- DSL.fieldByName()

The first method is really useful for "plain SQL", i.e. you could as well
just write arbitrary SQL in there:

DSL.field("(select 1 as x)");


What you're really looking for is the second method:

DSL.fieldByName("yearMonth");


Hope this helps
Lukas

2014-12-01 12:06 GMT+01:00 Gavriel Fleischer <[email protected]>:

> Hi,
>
> I'm using jooq  3.4.2 to generate queries for PostgreSQL DB. I set the dsl
> context to Dialect.POSTGRES. When I use the generated constants, everything
> is fine, jooq adds the necessary double quotes, but when I start to write
> "custom" sql, then there are no quotes.
>
> For example:
>
> dslContext.select(TABLE.COL1, TABLE.COL2).from(TABLE); // everything is
> with the double quotes
>
> or:
>
> SelectHavingStep<Record> t = dslContext.select(TABLE.DATE.substring(1, 4
> ).concat(TABLE.DATE.substring(6, 2)).cast(Integer.class).as("yearMonth")
> ).from(TABLE.as("t"));
>
>
> generates:
>
>
> cast((substring(cast("Table"."Date" as varchar), 1, 4) || 
> substring(cast("Table"."Date" as varchar), 6, 2)) as int) as "yearMonth"
>
>
> But when I try to use it, as a sub-select and I need to relate to the 
> "yearMonth" column alias:
>
>
> dslContext.select(field("yearMonth")).from(t.asTable("t"))
>
>
> In the generated sql yearMonth is not in double quotes.
>
>
> Is there a way to force the quotes also around the "custom" table and column 
> aliases?
>
>  --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to