Hi all,
Postgres seems to demand that you specify "ORDER BY" once per
"unioned" query.
This works:
=> SELECT id FROM output UNION SELECT id FROM output ORDER BY id LIMIT
1;
id
------
2020
(1 row)
This doesn't:
=> SELECT id FROM output ORDER BY id UNION SELECT id FROM output ORDER
BY id LIMIT 1;
ERROR: syntax error at or near "UNION"
LINE 1: SELECT id FROM output ORDER BY id UNION SELECT id FROM
outpu...
^
... jOOQ on the other hand, seems to assume that order by is specified
per "query part":
This gives an "cannot find symbol" error on "orderBy":
Static.jooq().selectFrom(Output.OUTPUT).union(Static.jooq().selectFrom(Output.OUTPUT)).orderBy(Output.ID);
This works (well, at least my IDE allows me to type this):
Static.jooq().selectFrom(Output.OUTPUT).orderBy(Output.ID).union(Static.jooq().selectFrom(Output.OUTPUT).orderBy(Output.ID));
I think Postgres is right here, but i'm not 100% sure.
- Sander