[5.7] Add support for identity columns in PostgreSQL 10+ #26096
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since PostgreSQL 10 the preferred method of defining auto increment
columns is to use SQL standard identity columns instead of SERIAL pseudo-types
COLUMN TYPE GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
See https://www.postgresql.org/docs/10/static/sql-createtable.html
Identity columns fix issues with SERIAL pseudo-types:
as explained by the author of the patch
PostgreSQL 10 has a pretty wide adoption and is a default version on Forge. More over the next major version PostgreSQL 11 is coming in a week or two.
This PR allows to define an identity column without introducing BC.
produces
always()
can be optionally used to make sure that a sequence value takes precedence over the user inputgives us
generatedAs()
optionally accepts astring
or anExpression
containing sequence options, i.e.produces
An identity column does not necessarily have to be an
increments
one (PK
)produces