Closed
Description
Is your feature request related to a problem? Please describe.
Today, I use SQLAlchemy to reflect and inspect Postgres tables. People are starting to move away from SERIAL
types to using GENERATED BY DEFAULT AS IDENTITY
and GENERATED ALWAYS AS IDENTITY
.
For example if I:
CREATE TABLE testidentity (id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, name VARCHAR NOT NULL, optional VARCHAR);
When I use sqlalchemy.inspect
to eventually get_columns
I'm given:
[{'name': 'id',
'type': BIGINT(),
'nullable': False,
'default': None,
'autoincrement': False,
'comment': None},
{'name': 'name',
'type': VARCHAR(),
'nullable': False,
'default': None,
'autoincrement': False,
'comment': None},
{'name': 'optional',
'type': VARCHAR(),
'nullable': True,
'default': None,
'autoincrement': False,
'comment': None}]
But there is a default and it does autoincrement
Describe the solution you'd like
Support for describing these generated defaults as having a default and as autoincrementing (although the latter is less important)
Describe alternatives you've considered
Trying to inspect the metadata via some other library directly and working around SQLAlchemy
Additional context
N/A
Have a nice day!
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sigmavirus24 commentedon May 12, 2020
I'm also willing to assist with implementing this but I have no clue as to where to start as I've never contributed to this project before.
zzzeek commentedon May 12, 2020
this is possibly not trivial, not on the reflection side, but on the mechanics of INSERT. all of the PG internals assume SERIAL for autoincrement and getting this format to work would be the hard part.
jvanasco commentedon May 12, 2020
Further Reading:
zzzeek commentedon May 12, 2020
we do support computed columns in general however i think PG's "identity" is a separate syntax.
jvanasco commentedon May 12, 2020
Aside from reflection:
generated=OneOf(["always", "default"])
,**sequence_options
OVERRIDING SYSTEM VALUE
@zzzeek check out this link that goes into some of what is done regarding the auto-creation of serials. https://www.depesz.com/2017/04/10/waiting-for-postgresql-10-identity-columns/
CaselIT commentedon May 12, 2020
We should check if the
generated always as identity
is already piked up by the reflection logic in 1.4, since the syntax is the same as a normal compute column.zzzeek commentedon May 12, 2020
the syntax is not what we generate, I tried this:
and got
I think this looks like a totally different (but very similar) syntax. One proposal is to add this as a column option:
49 remaining items