Re: [sqlalchemy] Introspecting column constraints

2016-11-18 Thread Jonathan Rogers
Thanks for the help and suggestions. I understand that Constraint objects need to be bound to a Table to drop or create them. I thought there might be a general, straightforward way to find a Constraint by Table and name. I did find a such a way for Constraints defined on the Table. The approach

Re: [sqlalchemy] Introspecting column constraints

2016-11-18 Thread mike bayer
The reason AddConstraint/DropConstraint need the Constraint attached to the table is because ADD CONSTRAINT / DROP CONSTRAINT in SQL require the table name, as these are related to ALTER TABLE . I recommend you use Alembic ops to emit ADD CONSTRAINT / DROP CONSTRAINT without requiring Table

Re: [sqlalchemy] Introspecting column constraints

2016-11-18 Thread Jonathan Rogers
Yes, the constraints are defined in Python and have names explicitly defined. The CheckConstraint I need to use is defined in a @declared_attr method for the column in a base class from which the mapped class inherits. I did find the CheckConstraint I need in

[sqlalchemy] Re: Selecting distinct entries based on max timestamp

2016-11-18 Thread Jonathan Rogers
On Friday, November 18, 2016 at 2:08:05 PM UTC-5, Paul Giralt wrote: > > I'm having trouble figuring out how to accomplish this task using > SQLAlchemy. Basically I have a table that maps a user's skill levels as > follows: > > class Skillmap(db.Model): > __tablename__ = 'skillmap' >

Re: [sqlalchemy] Selecting distinct entries based on max timestamp

2016-11-18 Thread mike bayer
On 11/18/2016 02:08 PM, Paul Giralt wrote: I'm having trouble figuring out how to accomplish this task using SQLAlchemy. Basically I have a table that maps a user's skill levels as follows: class Skillmap(db.Model): __tablename__ = 'skillmap' id = db.Column(db.UUID(),

Re: [sqlalchemy] Introspecting column constraints

2016-11-18 Thread mike bayer
Assuming here your constraints are already defined in Python and we are not talking about using reflection, we're talking about the CHECK constraint objects you've already built. If they are defined for a Table then they would be in table.constraints. If you have them on the Column then it's

[sqlalchemy] Introspecting column constraints

2016-11-18 Thread Jonathan Rogers
I have a Declarative-instrumented class with several constraints, some defined at the table level and some on a column. AFAICT, all the constraints are configured correctly because they are rendered correctly by CreateTable() when called with the class's Table instance. In order to import some

[sqlalchemy] Selecting distinct entries based on max timestamp

2016-11-18 Thread Paul Giralt
I'm having trouble figuring out how to accomplish this task using SQLAlchemy. Basically I have a table that maps a user's skill levels as follows: class Skillmap(db.Model): __tablename__ = 'skillmap' id = db.Column(db.UUID(), primary_key=True) user_id = db.Column(db.UUID(),

Re: [sqlalchemy] Column value determined as a function return on INSERT

2016-11-18 Thread mike bayer
On 11/18/2016 11:25 AM, Alexander O'Donovan-Jones wrote: That's a cool idea, but it would need to reference the instance we've created to use the `id` atribute. I was almost going to ask if that's what you meant, but you didn't specify that in your question. Simon's answer contains the

Re: [sqlalchemy] Column value determined as a function return on INSERT

2016-11-18 Thread Simon King
You can provide a function for the default value, and the function can receive the current statement context as a parameter. This context gives you access to the rest of the insert statement, including values of other parameters:

Re: [sqlalchemy] Column value determined as a function return on INSERT

2016-11-18 Thread Alexander O'Donovan-Jones
That's a cool idea, but it would need to reference the instance we've created to use the `id` atribute. ie the sql would be `select max(version)+1 from responses where id = :id` On Friday, 18 November 2016 14:39:52 UTC, Mike Bayer wrote: > > > > On 11/18/2016 09:10 AM, Alexander O'Donovan-Jones

Re: [sqlalchemy] Column value determined as a function return on INSERT

2016-11-18 Thread mike bayer
On 11/18/2016 09:10 AM, Alexander O'Donovan-Jones wrote: I'm currently working on using the ORM features of sqlalchemy with a legacy database table. The table can be roughly described like this: class APIResponse(Base): __tablename__ = 'responses' id = Column(Text,

[sqlalchemy] Column value determined as a function return on INSERT

2016-11-18 Thread Alexander O'Donovan-Jones
I'm currently working on using the ORM features of sqlalchemy with a legacy database table. The table can be roughly described like this: class APIResponse(Base): __tablename__ = 'responses' id = Column(Text, primary_key=True) version = Column(Integer, primary_key=True) payload =

Re: [sqlalchemy] How to run multiple statements/operations in a single transaction ?

2016-11-18 Thread Simon King
On Fri, Nov 18, 2016 at 11:43 AM, Santosh Sharma wrote: > I am using SQLAlchemy and postgres database. > > I want to do "Delete and Insert operation" on the table in a single > transaction without using orm. > > Say > table User > Column | Type|

[sqlalchemy] How to run multiple statements/operations in a single transaction ?

2016-11-18 Thread Santosh Sharma
I am using SQLAlchemy and postgres database. I want to do "Delete and Insert operation" on the table in a single transaction *without using orm.* Say *table User* Column | Type| Modifiers