From 1431dfcb01462a281c37cdde57408feba75db8b9 Mon Sep 17 00:00:00 2001 From: Murtuza Zabuawala Date: Fri, 16 Dec 2016 11:59:37 +0000 Subject: [PATCH] Show index columns in the correct order in RE-SQL. Fixes #1842 --- .../templates/index/sql/9.1_plus/column_details.sql | 3 ++- .../index_constraint/sql/get_constraint_cols.sql | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/column_details.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/column_details.sql index 2cf540a0c..c467eea92 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/column_details.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/column_details.sql @@ -27,4 +27,5 @@ FROM ( LEFT OUTER JOIN pg_operator op ON (op.oid = c.conexclop[i.attnum]) LEFT JOIN pg_attribute a ON (a.attrelid = i.indexrelid AND a.attnum = i.attnum) LEFT OUTER JOIN pg_collation coll ON a.attcollation=coll.oid - LEFT OUTER JOIN pg_namespace nspc ON coll.collnamespace=nspc.oid; + LEFT OUTER JOIN pg_namespace nspc ON coll.collnamespace=nspc.oid +ORDER BY i.attnum; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index_constraint/sql/get_constraint_cols.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index_constraint/sql/get_constraint_cols.sql index 4b2fee25a..61233c192 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index_constraint/sql/get_constraint_cols.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index_constraint/sql/get_constraint_cols.sql @@ -1,7 +1,14 @@ +{### +We need outer SELECT & dummy column to preserve the ordering +because we lose ordering when we use UNION +###} +SELECT * FROM ( {% for n in range(colcnt|int) %} {% if loop.index != 1 %} -UNION SELECT pg_get_indexdef({{ cid|string }}, {{ loop.index|string }}, true) AS column +UNION SELECT pg_get_indexdef({{ cid|string }}, {{ loop.index|string }}, true) AS column, {{ n }} AS dummy {% else %} -SELECT pg_get_indexdef({{ cid|string }} , {{ loop.index|string }} , true) AS column +SELECT pg_get_indexdef({{ cid|string }} , {{ loop.index|string }} , true) AS column, {{ n }} AS dummy {% endif %} -{% endfor %} \ No newline at end of file +{% endfor %} +) tmp +ORDER BY dummy \ No newline at end of file