Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
| От | Jesper K. Pedersen |
|---|---|
| Тема | Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly |
| Дата | |
| Msg-id | 44781BCC.7000607@solnet.homeip.net обсуждение исходный текст |
| Ответ на | Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly (Andrew Sullivan <ajs@crankycanuck.ca>) |
| Список | pgsql-sql |
Andrew Sullivan wrote: <blockquote cite="mid20060526105037.GB5492@phlogiston.dyndns.org" type="cite"><pre wrap="">On
Fri,May 26, 2006 at 05:11:26PM +0700, andi wrote: </pre><blockquote type="cite"><pre wrap="">select rank() over(order
bytesteridpk ) as rank , * from tester;
I get the result is like this,
RANK TESTERIDPK TESTER_NAME
1 10 TESSS
2 90 NAMAAA
3 100 UUUUUUUU
How in postgres sql I get the same result , please help me, because iam
really frustating with this duty. </pre></blockquote><pre wrap="">
There's no built in for that that I know of. You could use a
temporary sequence to do it:
BEGIN;
CREATE SEQUENCE tempseq;
SELECT nextval('tempseq') as rank, testeridpk, tester_name FROM testersORDER BY testeridpk;
ROLLBACK;
which, I _think_, will get you what you want (i.e. that's not
tested). The ROLLBACK is just there to clean up the sequence. </pre></blockquote> You can not rely on the "order by"
tosort your date at fetch time, it will read the date adding the nextval(...) at read time and then sort it.<br /><br
/>Best regards<br /> Jesper K. Pedersen<br /><br />
В списке pgsql-sql по дате отправления: