Re: [sqlalchemy] Column vs Table constraints for Column(unique=True) in Postgres

2015-05-29 Thread rob
Thank Lucas. I've tried that as well. In all cases, SQLAlchemy always emits a table constraint. i.e., an additional CONSTRAINT clause in the CREATE TABLE command. Maybe I've poorly phrased my question and SQLAlchemy always emits table constraints? Here's an updated example. In all three

Re: [sqlalchemy] Column vs Table constraints for Column(unique=True) in Postgres

2015-05-29 Thread Mike Bayer
On 5/29/15 2:12 AM, r...@rosenfeld.to wrote: Thank Lucas. I've tried that as well. In all cases, SQLAlchemy always emits a table constraint. i.e., an additional CONSTRAINT clause in the CREATE TABLE command. Maybe I've poorly phrased my question and SQLAlchemy always emits table

Re: [sqlalchemy] Column vs Table constraints for Column(unique=True) in Postgres

2015-05-29 Thread rob
Thanks. Makes sense. On Friday, May 29, 2015 at 10:12:07 AM UTC-5, Michael Bayer wrote: On 5/29/15 2:12 AM, r...@rosenfeld.to javascript: wrote: Thank Lucas. I've tried that as well. In all cases, SQLAlchemy always emits a table constraint. i.e., an additional CONSTRAINT clause

Re: [sqlalchemy] Column vs Table constraints for Column(unique=True) in Postgres

2015-05-20 Thread Lucas Taylor
Unless you provide a name, the constraint will be anonymously named, so there is no difference between that and the shortcut. Provide a name argument to UniqueConstraint: __table_args__ = (UniqueConstraint('alt_id', name='uq_alt_id'),) You may also be interested in providing a naming

Re: [sqlalchemy] Column vs Table constraints for Column(unique=True) in Postgres

2015-05-17 Thread rob
Sorry it took my a while to test this, but I didn't see any difference in the SQL emitted. What did I miss? from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column from sqlalchemy import Integer from sqlalchemy import UniqueConstraint from sqlalchemy import

[sqlalchemy] Column vs Table constraints for Column(unique=True) in Postgres

2015-05-03 Thread rob
Is there a way to control whether DDL emitted by SQLAlchemy uses a column and/or table constraint for uniqueness? It seems the following class Part(Base): __tablename__ = 'part' third_party_id = Column(Integer, nullable=True, default=None, unique= True) emits a table constraint CREATE

Re: [sqlalchemy] Column vs Table constraints for Column(unique=True) in Postgres

2015-05-03 Thread Mike Bayer
sure, use UniqueConstraint directly. It's better to use that than the unique=True flag in any case. On 5/3/15 10:29 PM, r...@rosenfeld.to wrote: Is there a way to control whether DDL emitted by SQLAlchemy uses a column and/or table constraint for uniqueness? It seems the following |