summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/introspection.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-09-06 10:26:45 -0400
committerTim Graham <timograham@gmail.com>2017-09-27 11:00:04 -0400
commit1d8cfa36089f2d1295abad03a99fc3c259bde6b5 (patch)
tree458e608105acb5fe7e9db7e2c01c833df1673795 /django/db/backends/postgresql/introspection.py
parentea7ca5db302367d84f92a4cf0ca03ec62886a7ca (diff)
downloaddjango-1d8cfa36089f2d1295abad03a99fc3c259bde6b5.tar.gz
Fixed #28626 -- Dropped support for PostgreSQL 9.3.
Thanks Simon Charette for the introspection changes.
Diffstat (limited to 'django/db/backends/postgresql/introspection.py')
-rw-r--r--django/db/backends/postgresql/introspection.py22
1 files changed, 6 insertions, 16 deletions
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py
index f060546a53..30f764f2f0 100644
--- a/django/db/backends/postgresql/introspection.py
+++ b/django/db/backends/postgresql/introspection.py
@@ -145,17 +145,12 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
# Loop over the key table, collecting things as constraints. The column
# array must return column names in the same order in which they were
# created.
- # The subquery containing generate_series can be replaced with
- # "WITH ORDINALITY" when support for PostgreSQL 9.3 is dropped.
cursor.execute("""
SELECT
c.conname,
array(
SELECT attname
- FROM (
- SELECT unnest(c.conkey) AS colid,
- generate_series(1, array_length(c.conkey, 1)) AS arridx
- ) AS cols
+ FROM unnest(c.conkey) WITH ORDINALITY cols(colid, arridx)
JOIN pg_attribute AS ca ON cols.colid = ca.attnum
WHERE ca.attrelid = c.conrelid
ORDER BY cols.arridx
@@ -183,17 +178,13 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
"options": options,
}
# Now get indexes
- # The row_number() function for ordering the index fields can be
- # replaced by WITH ORDINALITY in the unnest() functions when support
- # for PostgreSQL 9.3 is dropped.
cursor.execute("""
SELECT
- indexname, array_agg(attname ORDER BY rnum), indisunique, indisprimary,
- array_agg(ordering ORDER BY rnum), amname, exprdef, s2.attoptions
+ indexname, array_agg(attname ORDER BY arridx), indisunique, indisprimary,
+ array_agg(ordering ORDER BY arridx), amname, exprdef, s2.attoptions
FROM (
SELECT
- row_number() OVER () as rnum, c2.relname as indexname,
- idx.*, attr.attname, am.amname,
+ c2.relname as indexname, idx.*, attr.attname, am.amname,
CASE
WHEN idx.indexprs IS NOT NULL THEN
pg_get_indexdef(idx.indexrelid)
@@ -206,9 +197,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
END as ordering,
c2.reloptions as attoptions
FROM (
- SELECT
- *, unnest(i.indkey) as key, unnest(i.indoption) as option
- FROM pg_index i
+ SELECT *
+ FROM pg_index i, unnest(i.indkey, i.indoption) WITH ORDINALITY koi(key, option, arridx)
) idx
LEFT JOIN pg_class c ON idx.indrelid = c.oid
LEFT JOIN pg_class c2 ON idx.indexrelid = c2.oid