ROW_NUMBER alias - Mailing list pgsql-sql

From Robins
Subject ROW_NUMBER alias
Date
Msg-id 36af4bed0705060901s36fed269ye5a8588eaffbd750@mail.gmail.com
Whole thread Raw
Responses Re: ROW_NUMBER alias  (Stefan Becker <pgsql@yukonho.de>)
List pgsql-sql
Hi,<br /><br />I needed ROW_NUMBER() in PostGresql and I did find the 'temporary sequence' method as a workaround and i
thinkit at least gets the job done relatively well, ... so no problems there. <br /><br />Its just that from a
usabilitypoint of view, isn't it better that we provide some kind of an aliasing mechanism here that allows a new user
to(unknowingly but) implicitly use a temporary sequence rather than make him use SubQuery with a COUNT(*) and a
comparisonoperator (with disastrous performance) instead ?? <br /><br />So for a new user :<br /><br />A query such as
this:<br /><br />    SELECT ROW_NUMBER() AS row_number , a, b, c<br />        FROM table<br />        WHERE table_id  =
973<br/>        ORDER BY record_date;<br /><br />is internally interpreted by the planner as : <br /><br />    CREATE
TEMPSEQUENCE rownum; <br /><br />    SELECT nextval('rownum') AS row_number , t.a, t.b, t.c<br />    FROM (<br />   
   SELECT a, b, c<br />        FROM table<br />        WHERE table_id  = 973<br />        ORDER BY record_date<br />   
)t;<br /><br />    DROP SEQUENCE rownum;<br /><br />   <br clear="all" />Any ideas ?<br />(Of what I remember, I think
tillrecently PostgreSql internally replaced 'MAX(x)' queries with a 'ORDER BY x DESC LIMIT 1' implicitly)<br /><br
/>--<br/>Robins  

pgsql-sql by date:

Previous
From: "Jaime Casanova"
Date:
Subject: Re: Sequence vs. Index Scan
Next
From: "Aaron Bono"
Date:
Subject: Re: Sequence vs. Index Scan