英文:
How to create a primary key using sqlalchemy of type 'generated always as identity'
问题
我正在使用PostgreSQL,并希望为以下DDL创建SQLAlchemy模型:
create table tbl(
tbl_id INT generated always as identity PRIMARY KEY,
tbl_x INT
)
如何使用SQLAlchemy创建这个表?
英文:
I'm using postgres, and want to create the SQLA model for the following DDL:
create table tbl(
tbl_id INT generated always as identity PRIMARY KEY,
tbl_x INT
)
How to create this table using sqlalchemy ?
答案1
得分: 1
Sure, here's the translated code snippet:
#...
from sqlalchemy import Identity
#...
tbl = Table('tbl', metadata_obj,
Column('tbl_id', Integer, Identity(always=True)),
Column('tbl_x', Integer),
)
英文:
#...
from sqlalchemy import Identity
#...
tbl = Table('tbl', metadata_obj,
Column('tbl_id', Integer, Identity(always=True))
Column('tbl_x', Integer),
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论