Re: [sqlalchemy] Column CheckConstraint() question

2018-05-07 Thread Rich Shepard
On Sun, 6 May 2018, Mike Bayer wrote: the second approach is probably more common, as it's more compact. Thanks, Mike. It works well here. Best regards, Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Mike Bayer
the second approach is probably more common, as it's more compact. On Sun, May 6, 2018 at 6:30 PM, Rich Shepard wrote: > On Sun, 6 May 2018, Mike Bayer wrote: > >> here is the correct way to construct and append the constraint: > > > Thanks, Mike. I tried following

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Rich Shepard
On Sun, 6 May 2018, Mike Bayer wrote: here is the correct way to construct and append the constraint: Thanks, Mike. I tried following the example from the docs and could not find what I missed. You provide two approaches. Is there a preference for one over the other, perhaps based on

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Mike Bayer
or more succinctly (note the comma at the end of the CheckConstraint to indicate a tuple): class Sites(Base): __tablename__ = 'locations' site_id = Column(Integer, primary_key=True) site_name = Column(String(16), nullable=False) data_type = Column(String(12), nullable=False)

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Mike Bayer
here is the correct way to construct and append the constraint: class Sites(Base): __tablename__ = 'locations' site_id = Column(Integer, primary_key=True) site_name = Column(String(16), nullable=False) data_type = Column(String(12), nullable=False) source = Column(String(64))

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Rich Shepard
On Sun, 6 May 2018, Rich Shepard wrote: I'm missing how to properly use the above in my models.py module. Mike, And I have read the brief description of the CHECK Contstraint in the 'Defining Constraints and Indexes' section of the docs. Rich -- SQLAlchemy - The Python SQL Toolkit and

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Rich Shepard
On Fri, 4 May 2018, Mike Bayer wrote: you're looking for a table-level check constraint with IN: table.append_constraint( CheckConstraint(table.c.data_type.in_('A', 'B', 'C')) ) Mike, I'm missing how to properly use the above in my models.py module. For example: class Sites(Base):

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-04 Thread Rich Shepard
On Fri, 4 May 2018, Mike Bayer wrote: you're looking for a table-level check constraint with IN: Mike, Oh. I missed that since I write my postgres schema constraints on the column. alternatively, just use the backend-agnostic Enum type with native=False:

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-04 Thread Mike Bayer
On Fri, May 4, 2018 at 4:49 PM, Rich Shepard wrote: > In postgres (and I believe also in sqlite3) values in a table column can > be restricted to certain values. > > In models.py the class Sites() includes this column: > > data_type = Column(String(12),

[sqlalchemy] Column CheckConstraint() question

2018-05-04 Thread Rich Shepard
In postgres (and I believe also in sqlite3) values in a table column can be restricted to certain values. In models.py the class Sites() includes this column: data_type = Column(String(12), nullable=False, CheckConstraint('Biogical', 'Chemical', 'Microbial', 'Physical',