retrieve row number - Mailing list pgsql-sql
From | Pascal Tufenkji |
---|---|
Subject | retrieve row number |
Date | |
Msg-id | 000301c71512$5f773130$ef64a8c0@pascolo Whole thread Raw |
Responses |
Re: retrieve row number
|
List | pgsql-sql |
<div class="Section1"><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana">Hi,</span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana">Can I retrieve the row number in a select statement? </span></font><p class="MsoNormal"><font face="Verdana"size="2"><span style="font-size:10.0pt; font-family:Verdana">For example : if I have the following table “foo”</span></font><p class="MsoNormal"><font face="Verdana"size="2"><span style="font-size:10.0pt; font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier">col1 | col2</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier">-----+-----</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier"> a | x</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier"> b | y</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier"> c | z</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana">select ?? as row_number, col1, col2 from foo;</span></font><p class="MsoNormal"><font face="Verdana"size="2"><span style="font-size:10.0pt; font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana">I should obtain the following result :</span></font><p class="MsoNormal"><font face="Verdana" size="2"><spanstyle="font-size:10.0pt; font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier">row_number | col1 | col2</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier">-----------+------+-----</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier"> 1 | a | x</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier"> 2 | b | y</span></font><p class="MsoNormal"><font face="Courier" size="2"><span style="font-size:10.0pt; font-family:Courier"> 3 | c | z</span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana">Thank you</span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; font-family:Verdana">Pascal</span></font></div>