Case insenstive field selection

27 views
Skip to first unread message

Joe

unread,
Sep 20, 2021, 8:17:48 AM9/20/21
to jOOQ User Group
Hello

Thanks a lot for jOOQ :)

When doing queries like this:
```dslContext
.select(DSL.count(table.field("SOME_FIELD")))
.from(table) ```

we would like "SOME_FIELD" to be taken in account in a case insensitive way.

For example we would like to be able to write both:
``` dslContext
.select(DSL.count(table.field("SOME_FIELD")))
.from(table)
```
and
``` dslContext
.select(DSL.count(table.field("some_field")))
.from(table) ```

Is it possible somehow?

At worst is there a way to force a case other than the one in the DB, for example having some_field in DB but using SOME_FIELD when querying?

Thanks in advance

Best regards
joseph

Lukas Eder

unread,
Sep 20, 2021, 8:58:13 AM9/20/21
to jOOQ User Group
Hi Joe,


On Mon, Sep 20, 2021 at 2:17 PM Joe <japa...@gmail.com> wrote:
Hello

Thanks a lot for jOOQ :)

When doing queries like this:
```dslContext
.select(DSL.count(table.field("SOME_FIELD")))
.from(table) ```

we would like "SOME_FIELD" to be taken in account in a case insensitive way.

For example we would like to be able to write both:
``` dslContext
.select(DSL.count(table.field("SOME_FIELD")))
.from(table)
```
and
``` dslContext
.select(DSL.count(table.field("some_field")))
.from(table) ```

Is it possible somehow?

You can write your own auxiliary column lookup API for the time being until this is ever supported:
 
At worst is there a way to force a case other than the one in the DB, for example having some_field in DB but using SOME_FIELD when querying?

You could generate jOOQ code based on an alternative schema using upper case identifiers and then make sure jOOQ won't quote any identifiers in its generated SQL. But that won't make jOOQ identifiers case insensitive, it will just use upper case, case sensitive identifiers instead of lower case ones.

I hope this helps,
Lukas

Joe

unread,
Sep 20, 2021, 11:31:07 AM9/20/21
to jOOQ User Group
Thanks a lot Lukas

i've a hard time seeing how to write my "own auxiliary column lookup API" apart from forking the source code and changing the Fields class, do i miss something?

thanks again

Lukas Eder

unread,
Sep 20, 2021, 11:58:04 AM9/20/21
to jOOQ User Group
static Field<?> myField(Table<?> table, String name) {
    Field<?> result = table.field(name);
    if (result == null)
        result = table.field(name.toUpperCase());
    if (result == null)
        result = table.field(name.toLowerCase());
    return result;
}

--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/2199d5a3-46cf-4697-b02b-3aedec7561f4n%40googlegroups.com.

Joe

unread,
Sep 21, 2021, 7:30:32 AM9/21/21
to jOOQ User Group
ok, thanks

some utils to use then, but not a way to change getting field everywhere

thanks again!
Reply all
Reply to author
Forward
0 new messages