I have a scheduled task that synchronize data from external source (Db Oracle 11g).
Here is the query i'm successfully executing.
Partner.select("addresses.*, partners.*").joins(:address).where('existing=1)
Now, I would like to split this request by set a limit and an offset:
Partner.select("addresses.*, partners.*").joins(:address).where('existing=1').limit(100).offset(100)
here is the query generated by active record and the error:
SELECT * FROM (
SELECT raw_sql_.*, rownum raw_rnum_
FROM (
SELECT ADDRESSES.*, PARTNERS.*
FROM PARTNERS INNER JOIN ADDRESSES
ON ADDRESSES.ID = PARTNERS.ID
WHERE (EXISTING=1)
) raw_sql_
WHERE rownum <= 200
)
WHERE raw_rnum_ > 100
ActiveRecord::StatementInvalid: Java::JavaSql::SQLSyntaxErrorException: ORA-00918: column ambiguously defined
Note: exactly the same error using kaminari (obviously):
Partner.select("addresses.*, partners.*").joins(:address).where('existing=1').page(1)