Dump Query Output to File with Header

Useful utility to dump query output to file along with the Header

Note: Must be a a superuser to copy to or from a file. Login to postgres database as postgres user to execute this command.

COPY (SELECT user_id FROM auth_user_groups WHERE group_id = 2) to '/tmp/sales_users.txt' WITH CSV HEADER;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s