Re: sequence not restarting in a for loop (actually semi-random numbers) - Mailing list pgsql-general

From Tom Lane
Subject Re: sequence not restarting in a for loop (actually semi-random numbers)
Date
Msg-id 17079.1226506623@sss.pgh.pa.us
Whole thread Raw
In response to sequence not restarting in a for loop (actually semi-random numbers)  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
Responses Re: sequence not restarting in a for loop (actually semi-random numbers)
List pgsql-general
Ivan Sergio Borgonovo <mail@webthatworks.it> writes:
>   insert into mytop (id,n) select id, nextval('tmp_seq')
>     from biglist join mylist on biglist.id=mylist
>     order by biglist.something limit 3;

I suspect you are expecting the nextval()s to be done after the LIMIT,
but actually they'll most likely be done before it, ie you're getting
a lot of unintended nextvals happening.  Try doing the ORDER BY/LIMIT
in a sub-select.

            regards, tom lane

pgsql-general by date:

Previous
From: Alan Hodgson
Date:
Subject: Re: merge 2 dumps
Next
From: Robert Fitzpatrick
Date:
Subject: Post to another db using pl/pgsql