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

2020-06-02 Thread Jonathan Vanasco
thanks mike!

On Monday, June 1, 2020 at 7:15:23 PM UTC-4, Mike Bayer wrote:
>
> 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
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/c2bf33e3-a43f-4829-8bb0-4135fd961a61%40googlegroups.com.


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 6:16 PM, Jonathan Vanasco wrote:
> 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 = sa.Column(
>  sa.Integer, sa.ForeignKey("domain.id"), primary_key=True
> )
> 
> I want to influence the creation of the primary key to be 
> ["acme_dns_server_id", "domain_id"]
> 
> In several projects I've worked on, the order has been important. (it can 
> affect query planning and caching)
> 
> I thought I had seen something in the docs several years ago, but I just 
> spend a few fruitless minutes trying to find it.
> 

> --
>  SQLAlchemy - 
>  The Python SQL Toolkit and Object Relational Mapper
> 
> http://www.sqlalchemy.org/
> 
>  To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
>  --- 
>  You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
>  To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
>  To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/6728fb39-f5d9-4c97-a8b3-7df7fd918efa%40googlegroups.com
>  
> .

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/c3a48f3a-ad38-4881-9bb8-da8006d45cf3%40www.fastmail.com.


[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 = sa.Column(
sa.Integer, sa.ForeignKey("domain.id"), primary_key=True
)



I want to influence the creation of the primary key to be 
["acme_dns_server_id", 
"domain_id"]

In several projects I've worked on, the order has been important.  (it can 
affect query planning and caching)

I thought I had seen something in the docs several years ago, but I just 
spend a few fruitless minutes trying to find it.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/6728fb39-f5d9-4c97-a8b3-7df7fd918efa%40googlegroups.com.