Hi,
my colleague has found a problem today, when he was applying #addLimit to queries in our system.
We are working with Oracle 11g using JOOQ 2.6.3.
As far as I know, there is no direct support for limit in this database. JOOQ is wrapping original query within another query with extra "rownum" column to fulfil the task.
The problem is the "trick" does not work when the original query has at least two columns with same name and this is very common case when joining. The result is ORA-00918 error (column ambiguously defined).
I have prepared a simplified queries to show the problem:
----------------------------------------------------
--before applying #addLimit(int)
select "FOLDER"."ID", "SUBJECT"."ID"
from "FOLDER"
left outer join "SUBJECT" on "FOLDER"."LANDLORD" = "SUBJECT"."ID"
--after applying #addLimit(int)
select * from (
select "limit_9992791".*, rownum as "rownum_9992791"
from (
select "FOLDER"."ID", "SUBJECT"."ID"
from "FOLDER"
left outer join "SUBJECT" on "FOLDER"."LANDLORD" = "SUBJECT"."ID"
) "limit_9992791"
where rownum <= (? + ?)
)
where "rownum_9992791" > ?
Result: ORA-00918: column ambiguously defined
----------------------------------------------------
The only workaround (temporary I hope) we were able to apply was to #fetchLazy into Cursor and skip+break the loop and manually apply the mappers within.
I have a hypothesis: the problem could be easily solved by providing unique aliases to every TableField used by the SelectQuery used to produce the query.
What do you think? Is it good idea? Is it easy to fix the library that way? Help!
Thanks,
Witold Szczerba