Just a thought
reviewer, March 17, 2005 - 2:31 pm UTC
I have seen cases where for some reason (usually not a valid one) people are overly conserned with having the sequence numbers completly in sync. I was wondering if creating a view like the one below would be a valid solution to that problem:
SELECT
row_number() over(order by id) as id
, ...rest of the columns
FROM
table t
That would always give the numbers in order, and you could even use an instead of trigger to do the updates(in order to match the row_number output with the id output).
March 17, 2005 - 3:50 pm UTC
the row_number() would give you a sequential number -- at a high cost. And it would be a number that is not imutable (usually a requirement, the number cannot change)
Sequences without skips are never useful
Mike Friedman, March 19, 2005 - 5:29 am UTC
I have yet to see an application with a real need for real time sequential item numbering.
All cases I have seen to date are purely esthetic (ie. "I want my order numbers in seqence, wah!") or do not require numbers set at insert (ie. Order Line Numbers which can just be displayed in order when needed or added after the fact to order lines).