Did you try something like this?

q1=session.query(P1.userid, P1.extra, P1.title, P1.body)
q2=session.query(P2.userid, "'X'", P2.title, P2.body)
q3=session.query(P3.userid, "'X'", P3.title, P3.body)

q=q1.union_all(q2).union_all(q3)


-- 
Mike Conley



On Wed, Aug 26, 2009 at 10:45 PM, Seth <seedifferen...@gmail.com> wrote:

>
> I have three different types of post tables with all of the same
> columns except that the first table has an extra column named
> "type" (placed in-between the 'user_id' and 'title' columns of the
> other tables). I want to do a UNION ALL that will combine the data
> from all these tables into a single list (with a blank value for the
> tables missing the "type" column), and then I want to sort the posts
> by creation date.
>
> However, try as I might, I cannot seem to get this to work without
> throwing me an ArgumentError of "All selectables passed to
> CompoundSelect must have identical numbers of columns; select #1 has 7
> columns, select #2 has 6". I suspect this has something to do with
> SQLAlchemy auto-magically reading the DeclarativeBase table classes.
>
>
> The SQL version of this query would look something like:
>
> SELECT 'cat1' as category, * FROM posts_1 UNION ALL SELECT 'cat2', id,
> user_id, 'NONE', title, body, created, updated FROM posts_2 UNION ALL
> SELECT  'cat3', id, user_id, 'NONE', title, body, created, updated
> FROM posts3 ORDER BY created DESC LIMIT 10
>
> How can I get this to translate into SQLAlchemy with the extra 'NONE'
> for the tables that don't have a "type" column without giving me the
> ArgumentError?
>
> Thanks,
> Seth
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to