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 2cf540a..c467eea 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 4b2fee2..61233c1 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
