Re: [sqlalchemy] forcing (composite) primary key order?

2020-06-01 Thread Mike Bayer
yes use the PrimaryKeyConstraint() construct https://docs.sqlalchemy.org/en/13/core/constraints.html?highlight=primarykeyconstraint#sqlalchemy.schema.PrimaryKeyConstraint here you'd want to put it in your __table_args__ and remove primary_key=True from each column On Mon, Jun 1, 2020, at

[sqlalchemy] forcing (composite) primary key order?

2020-06-01 Thread Jonathan Vanasco
is it possible to force the order of primary keys? for example in this setup... class AcmeDnsServer2Domain(Base): __tablename__ = "acme_dns_server_2_domain" acme_dns_server_id = sa.Column( sa.Integer, sa.ForeignKey("acme_dns_server.id"), primary_key=True ) domain_id =

Re: [sqlalchemy] Using CTE without JOIN

2020-06-01 Thread Mike Bayer
thanks for the easy test. you want your IN to be against "SELECT * FROM cte" so you need to tell it to select() from that CTE: parent_cte = session.query(Parent).cte("parent_cte") query = ( session.query(Child).filter(Child.parent_id.in_(parent_cte.select())).all() ) if you just put the CTE in

[sqlalchemy] Using CTE without JOIN

2020-06-01 Thread Marat Sharafutdinov
from sqlalchemy import Column, ForeignKey, Integer, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker Base = declarative_base() class Parent(Base): __tablename__ = 'parents' id = Column(Integer, primary_key=True) class