From: Mike Bayer Date: Wed, 5 Oct 2011 15:47:19 +0000 (-0400) Subject: - Fixed bug related to [ticket:2141] whereby the X-Git-Tag: rel_0_7_3~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=879c932018fd22573163c76042761ce98ccaaaa3;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/CHANGES b/CHANGES index 0760031f9d..2119269bb9 100644 --- a/CHANGES +++ b/CHANGES @@ -219,6 +219,11 @@ CHANGES PG. [ticket:2290]. Thanks to Ryan P. Kelly for the patch. + - 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. + - Reflection functions for Table, Sequence no longer case insensitive. Names can be differ only in case and will be correctly distinguished. [ticket:2256] diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index b3be7bc998..7cc4a1e689 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)