[Sqlalchemy-tickets] Issue #3343: regression in supporting reflection on PostgreSQL 8.4 (zzzeek/sql
Brought to you by:
zzzeek
|
From: Jon N. <iss...@bi...> - 2015-03-24 15:07:22
|
New issue 3343: regression in supporting reflection on PostgreSQL 8.4 https://bitbucket.org/zzzeek/sqlalchemy/issue/3343/regression-in-supporting-reflection-on Jon Nelson: In ..../postgresql/base.py a change was made ( #3184, pull request bitbucket:30 ) to support additional smarts in reflecting indices and unique constraints in PostgreSQL. Unfortunately, this change is not compatible with PostgreSQL 8.4 which does not have a 'conindid' column. While it's not elegant, I whipped up the following patch: ``` #!C diff -ur SQLAlchemy-1.0.0b3.orig/lib/sqlalchemy/dialects/postgresql/base.py SQLAlchemy-1.0.0b3/lib/sqlalchemy/dialects/postgresql/base.py --- SQLAlchemy-1.0.0b3.orig/lib/sqlalchemy/dialects/postgresql/base.py 2015-03-24 09:51:23.850734852 -0500 +++ SQLAlchemy-1.0.0b3/lib/sqlalchemy/dialects/postgresql/base.py 2015-03-24 09:59:38.201019680 -0500 @@ -2605,7 +2605,7 @@ SELECT i.relname as relname, ix.indisunique, ix.indexprs, ix.indpred, - a.attname, a.attnum, c.conrelid, ix.indkey%s + a.attname, a.attnum, %s, ix.indkey%s FROM pg_class t join pg_index ix on t.oid = ix.indrelid @@ -2613,11 +2613,7 @@ left outer join pg_attribute a on t.oid = a.attrelid and %s - left outer join - pg_constraint c - on (ix.indrelid = c.conrelid and - ix.indexrelid = c.conindid and - c.contype in ('p', 'u', 'x')) + %s WHERE t.relkind IN ('r', 'v', 'f', 'm') and t.oid = :table_oid @@ -2629,8 +2625,14 @@ # version 8.3 here was based on observing the # cast does not work in PG 8.2.4, does work in 8.3.0. # nothing in PG changelogs regarding this. + "c.conrelid" if self.server_version_info >= (9, 0) else "NULL as conrelid", "::varchar" if self.server_version_info >= (8, 3) else "", - self._pg_index_any("a.attnum", "ix.indkey") + self._pg_index_any("a.attnum", "ix.indkey"), + """left outer join + pg_constraint c + on (ix.indrelid = c.conrelid and + ix.indexrelid = c.conindid and + c.contype in ('p', 'u', 'x'))""" if self.server_version_info >= (9, 0) else "" ) t = sql.text(IDX_SQL, typemap={'attname': sqltypes.Unicode}) ``` If you would prefer a pull request, I *might* be able to do that. |