4 ms·
> 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 queri
by mulander 7y ago
> 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.
- irrational 7y agoOur 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.