]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug related to [ticket:2141] whereby the
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 5 Oct 2011 15:47:19 +0000 (11:47 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 5 Oct 2011 15:47:19 +0000 (11:47 -0400)
    same modified index behavior in PG 9 affected
    primary key reflection on a renamed column.
    [ticket:2291].  Also in 0.6.9.

CHANGES
lib/sqlalchemy/dialects/postgresql/base.py

diff --git a/CHANGES b/CHANGES
index 0760031f9dcb7fd24bb13795daff49e83dbaf5fa..2119269bb942c72cb3eafc6626cf8c7a6a37aa64 100644 (file)
--- 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]
index b3be7bc998bc18bf5b001972df9666d69b7b6a4e..7cc4a1e6893eadc122d6d17372b2bb1e3f69b8f9 100644 (file)
@@ -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)