You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
H2 doesn't really support row expressions, but jOOQ can emulate them using H2's syntactically equivalent array notation (implemented with #1905), except if the IN predicate's subquery usese column aliases, e.g.
assertEquals(asList(1, 2),
create().select(TBook_ID())
.from(TBook())
.where(row(TBook_ID(), TBook_AUTHOR_ID()).in(
select(val(1).as("x"), val(1).as("y")) // Alias here
.unionAll(
select(val(2).as("x"), val(1).as("y"))) // Alias here
.unionAll(
select(TBook_ID().as("x"), TBook_ID().as("y")).from(TBook())))) // Alias here
.orderBy(TBook_ID())
.fetch(0, Integer.class));
The aliases are necessary in some other databases, as subqueries are not allowed to either:
Have unnamed columns
Have two columns of the same (generated) name "1"
But in H2, the following invalid SQL is generated:
select"PUBLIC"."T_BOOK"."ID"from"PUBLIC"."T_BOOK"where ("PUBLIC"."T_BOOK"."ID", "PUBLIC"."T_BOOK"."AUTHOR_ID") in (
(
select ( -- Wrapping subquery result in array1"x",
1"y"
)
)
union all (
select ( -- Wrapping subquery result in array2"x",
1"y"
)
)
union all (
select ( -- Wrapping subquery result in array"PUBLIC"."T_BOOK"."ID""x",
"PUBLIC"."T_BOOK"."ID""y"
)
from"PUBLIC"."T_BOOK"
)
)
order by"PUBLIC"."T_BOOK"."ID"
This would be a more correct solution:
select"PUBLIC"."T_BOOK"."ID"from"PUBLIC"."T_BOOK"where ("PUBLIC"."T_BOOK"."ID", "PUBLIC"."T_BOOK"."AUTHOR_ID") in (
select ("x", "y") from (
(
select1"x",
1"y"
)
union all (
select2"x",
1"y"
)
union all (
select"PUBLIC"."T_BOOK"."ID""x",
"PUBLIC"."T_BOOK"."ID""y"from"PUBLIC"."T_BOOK"
)
)
)
order by"PUBLIC"."T_BOOK"."ID"
The text was updated successfully, but these errors were encountered:
H2 doesn't really support row expressions, but jOOQ can emulate them using H2's syntactically equivalent array notation (implemented with #1905), except if the
IN
predicate's subquery usese column aliases, e.g.The aliases are necessary in some other databases, as subqueries are not allowed to either:
"1"
But in H2, the following invalid SQL is generated:
This would be a more correct solution:
The text was updated successfully, but these errors were encountered: