snippetsqlMajor
How to list all table columns in sorted order on Postgres?
Viewed 0 times
ordercolumnsallpostgreshowsortedlisttable
Problem
I know that
\d table_name lists all columns for that table, but is there a way to list them sorted in alphabetical order?Solution
Generally, use the
information_schema:SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'blah'
ORDER BY column_name ASC;Code Snippets
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'blah'
ORDER BY column_name ASC;Context
StackExchange Database Administrators Q#57130, answer score: 30
Revisions (0)
No revisions yet.