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.