\copy only select rows

Started by Ow Mun Hengover 18 years ago3 messagesgeneral
Jump to latest
#1Ow Mun Heng
Ow.Mun.Heng@wdc.com

Is there a way to do a dump of a database using a select statement?

eg: \copy trd to 'file' select * from table limit 10

#2A. Kretschmer
andreas.kretschmer@schollglas.com
In reply to: Ow Mun Heng (#1)
Re: \copy only select rows

am Thu, dem 30.08.2007, um 14:59:06 +0800 mailte Ow Mun Heng folgendes:

Is there a way to do a dump of a database using a select statement?

A complete database or just a simple table?

eg: \copy trd to 'file' select * from table limit 10

Since 8.2 you can use COPY (select * from table) TO 'file'.

Other solution, use a regular UNIX-Shell and psql, a la

echo "select * from table limit 10;" | psql <database> > file

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

#3Ow Mun Heng
Ow.Mun.Heng@wdc.com
In reply to: A. Kretschmer (#2)
Re: \copy only select rows

On Thu, 2007-08-30 at 09:14 +0200, A. Kretschmer wrote:

am Thu, dem 30.08.2007, um 14:59:06 +0800 mailte Ow Mun Heng folgendes:

Is there a way to do a dump of a database using a select statement?

A complete database or just a simple table?

a simple table.. couple million records, want some of them for testing..
say ~100pcs

(right now, using insert into foo select * fromt able limit 10)

eg: \copy trd to 'file' select * from table limit 10

Since 8.2 you can use COPY (select * from table) TO 'file'.

superuser priviledge only right?

Other solution, use a regular UNIX-Shell and psql, a la

echo "select * from table limit 10;" | psql <database> > file

I want them to be in comma delimited format.. will the output be
importable again using \copy into pg?