On 3/21/20 1:45 PM, pabloa98 wrote:


On Sat, Mar 21, 2020 at 12:08 PM Peter J. Holzer <hjp-pg...@hjp.at <mailto:hjp-pg...@hjp.at>> wrote:



    And I think that "care about gaps -> sequence doesn't work" is a
    knee-jerk reaction. It's similar to "can't parse HTML with regexps".
    True in the general case, and therefore people tend to blurt it out
    every time the topic comes up. But not necessarily true in specific
    cases. As I wrote above, there is no perfect solution - so you have to
    think about the actual requirements and the consequences of various
    solutions - and maybe using a sequence is the best (or least bad)
    solution.


OK. In that case, I will proceed with the millions of sequences. We will see.

Anyway, It will be awesome if we have a sequence data type in a future version of postgresql. They will solve a lot of problems similar to this one.

Actually there are already two:

https://www.postgresql.org/docs/12/datatype-numeric.html#DATATYPE-SERIAL

https://www.postgresql.org/docs/12/sql-createtable.html
"
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]

This clause creates the column as an identity column. It will have an implicit sequence attached to it and the column in new rows will automatically have values from the sequence assigned to it.
"

What you want is a built in method to pull from different sequences depending on the value of another column or values from multiple columns in the same table.



Pablo



--
Adrian Klaver
adrian.kla...@aklaver.com


Reply via email to