I followed the answer indicated below to export all tables in CSV.

How can I dump all tables to CSV for a PostgreSQL schema?

However, I also need to specify the column order. I am thinking about running this query

select * from information_schema.columns order by table_name, column_name


select column_name1, column_name2 from table_name.

Is it possible to script that kind of logic with psql (Or any other program) ?


  • What order do you want the columns in? Alphabetic?
    – dwhitemv
    Nov 11, 2022 at 20:33
  • Yes exactly ! In alphabetical order, it would be perfect
    – Dev01
    Nov 12, 2022 at 11:26


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.