-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

When selecting against joined tables, SQLAlchemy always use the
"ON join_condition" form.

The problem with this is that when the joined columns have the same
name, they are included 2 times in the result set.


Example (PostgreSQL):

CREATE TABLE foo (
    id TEXT PRIMARY KEY,
    x INTEGER
);

CREATE TABLE bar (
    a INTEGER PRIMARY KEY,
    id TEXT REFERENCES (foo.id) NOT NULL
);

INSERT INTO foo VALUES ('ID', 777);
INSERT INTO bar VALUES (0, 'ID');

SELECT * FROM foo JOIN bar ON foo.id = bar.id;
 id |  x  | a | id
- ----+-----+---+----
 ID | 777 | 0 | ID


If we use "USING ( join_column [, ...] )", instead, only one of each
pair of equivalent columns will be included in the join output, not both.


SELECT * FROM foo JOIN bar USING (id);
 id |  x  | a
- ----+-----+---
 ID | 777 | 0


Is it possible to change SQLAlchemy to use the second form when the
joined columns have the same name?

In alternative, this can be requested explicitly, as example:

class Join(FromClause):
    __visit_name__ = 'join'

    def __init__(self, left, right, onclause=None, using=None,
                 isouter=False):
        ...

When specified ``using`' take precedence over `onclause`.



Thanks   Manlio Perillo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlCa7CwACgkQscQJ24LbaUQeyQCeIqMJyemQWfe+OKoMU0wV7Z+y
+0oAn3dVqCIA9QeEtysbBHMTMDp4CpS2
=ey+X
-----END PGP SIGNATURE-----

-- 
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