using DSL.max with custom field

40 views
Skip to first unread message

Jacob G

unread,
Oct 27, 2016, 11:54:57 AM10/27/16
to jOOQ User Group
I'm trying to write a select query using DSL.max on a custom field, i.e., a DSL.field constructed using jsonb, but I'm getting this error when running the following query (specific names obscured):

Field (cast("schema"."table"."field" #>> '{property}' AS schema.enum_type)) is not contained in Row (max(cast("schema"."table"."field" #>> '{property}' AS schema.enum_type)))

It looks like DSL.max requires that the field be a real column in the table, i.e., in the Record definition. Am I understand that correctly? Is there a way to do what I'm trying?

Thanks!

Jacob G

unread,
Oct 27, 2016, 12:14:42 PM10/27/16
to jOOQ User Group
Never mind. I figured out the issue. DSL.max works fine, but I need to give the field a name (i.e.,g DSL.max(...).as("myfield"), and then reference that name in the fetchOne("myfield", String.class) call.

Lukas Eder

unread,
Oct 27, 2016, 2:05:47 PM10/27/16
to jooq...@googlegroups.com
Hi Jacob,

Yes, that's one option. Another one is to pass the exact same reference to ResultQuery.fetchOne() or to Record.get(). e.g.

Field<?> max = DSL.max(...);
Object value =
DSL.using(configuration)
   .select(max)
   .from(...)
   .fetchOne(max);

You could even repeat the entire field expression, although that might be a bit tedious in your case:

Object value =
DSL.using(configuration)
   .select(DSL.max(...))
   .from(...)
   .fetchOne(DSL.max(...));

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.

Jacob G

unread,
Oct 27, 2016, 3:26:06 PM10/27/16
to jOOQ User Group
Thanks a lot Lukas. Yeah, I saw that works too, and prefer it over what I wrote in my last message.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages