sqljooqtrino

GROUP BY with "?" placeholders for Trino


Problem description in Trino
If the GROUP BY clause contains a ?, the query fails.
ie:

PREPARE stmt FROM
SELECT
    IF(origin = ?, 'LI', 'AB'),
    SUM(1)
FROM
    <catalog>.<table>
WHERE
    date = '2025-07-01'
GROUP BY 
    1;
EXECUTE stmt USING '<value>';

works, but

PREPARE stmt FROM
SELECT
    IF(origin = ?, 'LI', 'AB'),
    SUM(1)
FROM
    <catalog>.<table>
WHERE
    date = '2025-07-01'
GROUP BY 
    IF(origin = ?, 'LI', 'AB');
EXECUTE stmt USING '<value>', '<value>';

throws this error:

SQL Error [73]: Query failed (#20250807_145054_11734_hjgyj): line 2:3: 'IF((origin = ?), 'LI', 'AB')' must be an aggregate expression or appear in GROUP BY clause

Problem description with jOOQ
I don't need the value of the GROUP BY to be variable

GROUP BY 
    IF(origin = ?, 'LI', 'AB');

since I know it at compile time, but that's the way the org.jooq.Condition seems to be translated to the SQL PreparedStatement.
This is how I create the org.jooq.Condition:

DSL.field("origin").eq(<static value>)

Possible solution
Is there a way for the org.jooq.Condition to be created without the ? placeholder? So that the PreparedStatement is executed in Trino will be

GROUP BY 
    IF(origin = <static val>, 'LI', 'AB');

and not

GROUP BY 
    IF(origin = ?, 'LI', 'AB');

Solution

  • Just inline the bind value using DSL.inline(), i.e.

    DSL.field("origin").eq(DSL.inline(STATIC_VALUE))