]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Revised this very old issue where the Postgresql "get primary key"
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 14 Feb 2014 19:32:00 +0000 (14:32 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 14 Feb 2014 19:32:30 +0000 (14:32 -0500)
reflection query were updated to take into account primary key constraints
that were renamed; the newer query fails on very old versions of
Postgresql such as version 7, so the old query is restored in those cases
when server_version_info < (8, 0) is detected. #2291

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/dialects/postgresql/base.py

index 71aee218b397175ea29d4e58271b01bccb71eaaf..80217b12f9ffde4677db808372059613f493d86b 100644 (file)
 .. changelog::
     :version: 0.8.5
 
+    .. change::
+        :tags: bug, postgresql
+        :tickets: 2291
+
+        Revised this very old issue where the Postgresql "get primary key"
+        reflection query were updated to take into account primary key constraints
+        that were renamed; the newer query fails on very old versions of
+        Postgresql such as version 7, so the old query is restored in those cases
+        when server_version_info < (8, 0) is detected.
+
     .. change::
         :tags: bug, sql
         :tickets: 2957
index c451d46764d643549f29b15bd60028812bf01728..1eaa6f6e1f2aa66e8aba8e58f1de82e3e3c9ba74 100644 (file)
@@ -1824,7 +1824,21 @@ class PGDialect(default.DefaultDialect):
         table_oid = self.get_table_oid(connection, table_name, schema,
                                        info_cache=kw.get('info_cache'))
 
-        if self.server_version_info < (8, 4):
+        if self.server_version_info < (8, 0):
+            # the shortcoming of this query is that it will
+            # not detect a PK constraint that has been renamed.
+            # This query was removed with #2291, however it was reported
+            # that the newer queries do not work with PG 7 so here
+            # it is restored when old PG versions are detected.
+            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
+            """
+        elif self.server_version_info < (8, 4):
             # unnest() and generate_subscripts() both introduced in
             # version 8.4
             PK_SQL = """