diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-10-05 11:47:19 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-10-05 11:47:19 -0400 |
commit | 879c932018fd22573163c76042761ce98ccaaaa3 (patch) | |
tree | 126d13e87f250985ef3eb49c83cb1af84c8c34bc /lib/sqlalchemy/dialects/postgresql/base.py | |
parent | 771f6fba4c76d4c65c4326cbbc5ce1d909d7358a (diff) | |
download | sqlalchemy-879c932018fd22573163c76042761ce98ccaaaa3.tar.gz |
- Fixed bug related to [ticket:2141] whereby the
same modified index behavior in PG 9 affected
primary key reflection on a renamed column.
[ticket:2291]. Also in 0.6.9.
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index b3be7bc99..7cc4a1e68 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1308,13 +1308,19 @@ class PGDialect(default.DefaultDialect): def get_primary_keys(self, connection, table_name, schema=None, **kw): table_oid = self.get_table_oid(connection, table_name, schema, info_cache=kw.get('info_cache')) + PK_SQL = """ - SELECT attname FROM pg_attribute - WHERE attrelid = ( - SELECT indexrelid FROM pg_index i - WHERE i.indrelid = :table_oid - AND i.indisprimary = 't') - ORDER BY attnum + SELECT a.attname + FROM + pg_class t + join pg_index ix on t.oid = ix.indrelid + join pg_attribute a + on t.oid=a.attrelid and a.attnum=ANY(ix.indkey) + WHERE + t.oid = :table_oid and + ix.indisprimary = 't' + ORDER BY + a.attnum """ t = sql.text(PK_SQL, typemap={'attname':sqltypes.Unicode}) c = connection.execute(t, table_oid=table_oid) |