Closed
Description
Describe the use case
A method to tell if a column is autoincremented or not.
Preference would be to have something like Column.is_autoincremented: bool
, but a Table.get_autoincrement_column() -> Column
(as suggested by @zzzeek) would work fine too.
Example Use
for c in table.c:
show_in_create_form = not c.is_autoincremented
# Create input widget from column
Or, with an actual implementation:
https://github.com/aio-libs/aiohttp_admin/blob/master/aiohttp_admin/backends/sqlalchemy.py#L43
Additional context
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
CaselIT commentedon Feb 10, 2023
Hi,
I'm not sure if excluding only incrementing columns would be sufficient for your use case.
Computed columns are also generated by the db, and depending on the db they may not be set in the insert. Postgresql is one such db (requires default to be used for generated always columns)
Dreamsorcerer commentedon Feb 10, 2023
You may be right, would a
is_computed
or similar be possible? Ultimately, I just want something which tells me this column should not have a value passed in for a normal insert.CaselIT commentedon Feb 10, 2023
there is already
.computed
that you can test for nonezzzeek commentedon Feb 10, 2023
if you want any server default col you need to look at server_default also
zzzeek commentedon Feb 10, 2023
though for now, the only API that's not public is the "which col is autoincrement" , so we can make that public. I do think it should be for Table though because it's the Table that chooses this, not the column
Dreamsorcerer commentedon Feb 10, 2023
But, that returns
None
on autoincrement. So, I guess I'll need to check both autoincrement and computed.Yes, already thought about looking at default/server_default/nullable to decide whether a field is required or not.
CaselIT commentedon Feb 10, 2023
well yes, an autoincrement or itentity column is not a computed one (as identified by "generated always as")
3 remaining items