Re: [sqlalchemy] One-to-one relationship as a boolean flag

2015-07-08 Thread Mike Bayer
On 7/8/15 12:15 AM, Pedro Werneck wrote: Let's say I have a table 'user', and for backwards compatibility reasons I have a single-column table named 'user_active' which is basically just a foreign key used as a boolean flag. I need my User model to have the 'active' field as a boolean

[sqlalchemy] Trying to join a session query to a union

2015-07-08 Thread Horcle
Hi all, I have the following union query: q1 = db.session.query(label('sid',distinct(left.c.patient_sid))) q2 = db.session.query(label('sid',distinct(right.c.patient_sid))) query = q1.union_all(q2) Which works just fine. And I have the following query to which I would like to join this:

Re: [sqlalchemy] convert PostgreSQL to sqlite

2015-07-08 Thread c.buhtz
I tried this code. There are two objects in it. The second is just a new created one to check if everything goes right. It appears in the sqlite database. The first object is from the old PostgreSQL database. But it doesn't appear in the new sqlite database. There even is no error output and now

[sqlalchemy] Re: Trying to join a session query to a union

2015-07-08 Thread Jonathan Vanasco
you probably need to modify the various objections with a `.select()` or `.subquery()` e.g: query_select = query.select() q = intersect.join(query_select, query_select.c.sid, intersect.c.sid) pay attention to the docs on what the various methods return. some return a selectable, others

[sqlalchemy] Re: Trying to join a session query to a union

2015-07-08 Thread Horcle
For the record, this should have a '==' for the join condition: q = intersect.join(query_select, query_select.c.sid == intersect.c.sid) On Wednesday, July 8, 2015 at 7:48:54 PM UTC-5, Horcle wrote: Weird, I had tried using the subquery() method earlier, but it didn't work. Not sure why, but

Re: [sqlalchemy] convert PostgreSQL to sqlite

2015-07-08 Thread c.buhtz
Forget the old code. I needed to use make_transient() This example code work nearly fine (FOREIGN KEY constraints not used in sqlite) #!/usr/bin/env python3 # -*- coding: utf-8 -*- import sqlalchemy as sa import sqlalchemy.ext.declarative as sad import sqlalchemy.orm as sao import

[sqlalchemy] Re: Trying to join a session query to a union

2015-07-08 Thread Horcle
Weird, I had tried using the subquery() method earlier, but it didn't work. Not sure why, but now it is returning the desired query object. (I guess stepping away from this for a few hours was a good idea, eh?!) Thanks! Greg-- On Wednesday, July 8, 2015 at 6:24:16 PM UTC-5, Jonathan Vanasco

[sqlalchemy] Using Postgres Composite Types

2015-07-08 Thread Vincent Catalano
I've been trying to get SQLAlchemy to work with Postgres composite types for the last couple days with no luck. I've implemented the PGCompositeType that Michael created in another post