PostgreSQL Table Column Order Bug

[expired user #7335]'s profile image [expired user #7335] posted 10 years ago in General Permalink
A recent build of HeidiSQL seems to have introduced a bug that results in the columns in tables being displayed out-of-order. This occurs in both the column list and the data browser. The most significant problem with this is that the column in the data browser have incorrect headings for the data contained in them.

I believe that the source of this problem is this query:
SELECT DISTINCT
a.attnum,
a.attname AS column_name,
FORMAT_TYPE(a.atttypid, a.atttypmod) AS data_type,
CASE a.attnotnull WHEN FALSE THEN 'YES' ELSE 'NO' END AS IS_NULLABLE,
com.description AS column_comment,
def.adsrc AS column_default,
NULL AS character_maximum_length
FROM pg_attribute AS a
JOIN pg_class AS pgc ON pgc.oid = a.attrelid
LEFT JOIN pg_description AS com ON (pgc.oid = com.objoid AND a.attnum = com.objsubid)
LEFT JOIN pg_attrdef AS def ON (a.attrelid = def.adrelid AND a.attnum = def.adnum)
WHERE a.attnum > 0
AND pgc.oid = a.attrelid
AND pg_table_is_visible(pgc.oid)
AND NOT a.attisdropped
AND pgc.relname = 'my_table';


I suspect this issue can be resolved by simply adding this line to the end of the query:
ORDER BY a.attnum;


Thanks.
Code modification/commit 418dec3 from ansgar.becker, 10 years ago, revision 8.3.0.4855
Sort columns by attnum. Fixes wrong order of column names in data grid. See http://www.heidisql.com/forum.php?t=16747
ansgar's profile image ansgar posted 10 years ago Permalink
Fixed in r4855

Please login to leave a reply, or register at first.