Show Databases, Tables and Columns in PostgreSQL

Man….why is it that every time I stop using PostgreSQL for more than a month I immediately forget how to list tables and columns? Here’s a listing for posterity. Show Databases MySQL: SHOW DATABASES; PostgreSQL \l Show Tables MySQL: SHOW TABLES; PostgreSQL \d Show Columns MySQL: SHOW COLUMNS; PostgreSQL \d+ tablename Show Yourself Out (exit) […]

Output a Postgres or MySQL Query to CSV

I find myself needing to output CSV from database queries a lot, and like an Alzheimer’s patient I am constantly forgetting how to do it. Here’s the quick run-down on how you get queries from your database into a CSV file. Postgres \f ‘,’ \a \t \o /tmp/output.csv SELECT column_id, column_name FROM table_name; \o \q […]