- changed title to automatically make sequences into server default?
- marked as proposal
document sequence + server default
Issue #3453
resolved
When I supply a primary key a custom Sequence the sequence is created but not attached to the primary key column. Tested only with PostgreSQL and SQLAlchemy 1.0.5
example code
from sqlalchemy import Column,Integer, Sequence
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
Base = declarative_base()
class TestCustomSeq(Base):
__tablename__ = 'testseq'
id = Column(Integer, Sequence('customseq'), primary_key=True)
alchemy_engine = create_engine('postgresql://gijs:gijs@localhost:5433/gijs', echo=True)
Base.metadata.create_all(alchemy_engine)
generated sql:
CREATE SEQUENCE customseq
COMMIT;
CREATE TABLE testseq (
id INTEGER NOT NULL,
PRIMARY KEY (id)
);
Comments (6)
-
repo owner -
Account Deleted reporter sure, I just didn't knew how to get this going but this results in what I want to accomplish! thanks.
-
Account Deleted reporter btw, if you supply optional=True to sequence it does t work, but the name is ignored. That is why I thought the usage was a bit inconsistent
-
repo owner - changed status to resolved
- add a subsection on how to use Sequence with server_default,
fixes
#3453
→ <<cset b861b7537c29>>
-
repo owner - add a subsection on how to use Sequence with server_default,
fixes
#3453
(cherry picked from commit b861b7537c29349da00793fc828226a68cded62d)
→ <<cset 981685c7b353>>
- add a subsection on how to use Sequence with server_default,
fixes
-
repo owner - changed title to document sequence + server default
- marked as task
- changed milestone to 1.0.6
- Log in to comment
if you'd like to make the Sequence a server default, specify the SQL expression you'd like as server_default:
im -1 on changing anything here. at most just a documentation update.