@Filip:
array notation seems to be more cost (character-wise) effective than values (). Also – please note that your code assumes that this query:
select id, nextval(’tmpseq’) as rank from test order by id limit 3
will not *order* rows, but will get them already ordered (presumably from index scan).