mysqljooq

Select NULL as column using JOOQ


I'm trying to select NULL as a column in my query using JOOQ, so basically something like this:

SELECT name, NULL as 'someColumn' FROM someTable;

I need to do this, because the result needs to include someColumn (as part of a data standard), but we do not have this information in our database. This works fine in plain SQL, but I'm struggling to reproduce this using JOOQ.

Does anyone know how to do this in a query of this form?

context.select(
    SOMETABLE.NAME,
    ... // Other columns here
    DSL.NULL.as("someColumn") // <-- This doesn't exist
)

Solution

  • You can use an inline value

    DSL.inline((String) null) // Or whatever type
    

    Depending on your database dialect or query usage, you may need to add a data type to that value, e.g.

    DSL.inline(null, SQLDataType.VARCHAR)