News for hackers. Stuff that matters.
Re:Amazon’s Consumer Business Turned Off Final Oracle Database by mulander on Wednesday October 16, 2019 @04:41AM (#21268302)
> replace rownum <= 1 with LIMIT 1

rownum is a pseudocolumn numbering entries, sorting the results will give you records in non increment rownum. On such queries rownum <= N will give you the record that was first in the results before sorting.

LIMIT will give you the first record after sorting.

So rownum != LIMIT and if you really want to implement the same logic you would need to use select row_number() over () as rownum in the ported query, put that into a subquery and filter with where rownum <= N in the outer level.

Example:

select * from (select row_number() over () as rownum, * from pg_class order by relname) as x where x.rownum < 5;

select * from pg_class order by relname LIMIT 5;

Will give two very different results.

The first one maps to oracle:

select * from pg_class where rownum < 5 order by relname;

The second one doesn't.

Re:Amazon’s Consumer Business Turned Off Final Oracle Database by irrational on Wednesday October 16, 2019 @12:49PM (#21272489)
Our Oracle queries are written like:

select * from ( select * from pg_class order by relname ) where rownum <= 1

So select * from pg_class order by relname limit 1

works for us.