Preferred usage for 'copy to' for a subset of data

Started by Jason L. Buberelover 18 years ago2 messagesgeneral
Jump to latest
#1Jason L. Buberel
jason@buberel.org

For recent postgres releases, is there any effective difference
(performance/memory/io) between:

create temp table foo as select * from bar where bar.date > '2007-01-01';
copy foo to '/tmp/bar.out';
drop table temp;

and this:

copy ( select * from bar where bar.date > '2007-01-01' ) to '/tmp/bar.out';

...that would lead me to use one method vs. the other on large data sets
(1M+ records)?

Just wondering,
Jason

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jason L. Buberel (#1)
Re: Preferred usage for 'copy to' for a subset of data

"Jason L. Buberel" <jason@buberel.org> writes:

For recent postgres releases, is there any effective difference
(performance/memory/io) between:

create temp table foo as select * from bar where bar.date > '2007-01-01';
copy foo to '/tmp/bar.out';
drop table temp;

and this:

copy ( select * from bar where bar.date > '2007-01-01' ) to '/tmp/bar.out';

Surely the latter will be faster, since it doesn't bother to store all
the data in a server temp table.

regards, tom lane