Gap-less sequence where multiple transactions with multiple tables are involved

前端 未结 4 563
一整个雨季
一整个雨季 2020-12-22 03:54

I have a requirement (by law) for a gap-less numbers on different tables. The IDs can have holes in them but not the sequences.

This is something I have to either so

4条回答
  •  没有蜡笔的小新
    2020-12-22 04:18

    Gap-less sequences are hard to come by. I suggest to use a plain serial column instead. Create a view with the window function row_number() to produce a gap-less sequence:

    CREATE VIEW foo AS
    SELECT *, row_number() OVER (ORDER BY serial_col) AS gapless_id
    FROM   tbl;
    

提交回复
热议问题