This is for the actual Schema branch (Sa 0.2 rev. 1468).

Using polymorphism as it is shown in the examples
creates a SQL query like this :

SELECT pjoin.info AS pjoin_info,
       pjoin.parent_id AS pjoin_parent_id,
       pjoin.type AS pjoin_type,
       pjoin.id AS pjoin_id
FROM (
  SELECT info.info AS info,
         contained.parent_id AS parent_id,
         contained.type AS type,
         info.id AS id
  FROM contained JOIN info ON contained.id = info.id
     UNION ALL
       SELECT NULL AS info,
              parent_id,
              type,
              id
       FROM (
         SELECT contained.id AS id,
                contained.parent_id AS parent_id,
                contained.type AS type
         FROM contained
         WHERE contained.type = "contained"
       )
) AS pjoin
ORDER BY pjoin.id

Everything works fine with SQLite.

With MySQL this produces :
SQLError: (OperationalError) (1248, 'Every derived table must have its own 
alias')


Using an alias in the select of the UNION ALL solves the problem :

SELECT pjoin.info AS pjoin_info,
       pjoin.parent_id AS pjoin_parent_id,
       pjoin.type AS pjoin_type,
       pjoin.id AS pjoin_id
FROM (
  SELECT info.info AS info,
         contained.parent_id AS parent_id,
         contained.type AS type,
         info.id AS id
  FROM contained JOIN info ON contained.id = info.id
     UNION ALL
       SELECT NULL AS info,
              pjoin_1.parent_id,
              pjoin_1.type,
              pjoin_1.id
       FROM (
         SELECT contained.id AS id,
                contained.parent_id AS parent_id,
                contained.type AS type
         FROM contained
         WHERE contained.type = "contained"
       ) as pjoin_1                      <----------------------------
) AS pjoin
ORDER BY pjoin.id


Jürgen



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to