I am mikek's Blog

The personal blog of Mike Karthauser, who you may know from Brightstorm Limited or the internet.

Exporting results of a query as sql in postgres

Expanding on last weeks post, below is a way to get results from a certain query out into a file,

create table TMP_TABLE as select * from foo;

pg_dump -h localhost -U DATABASE_USERNAME --data-only --column-inserts -t TMP_TABLE DATABASE_NAME >OUTPUT_FILE_NAME ;

essentially, create a new table with your query in it and then use pg_dump to get it into a file.


Filed under: development, , , ,

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

mikek on twitter

%d bloggers like this: