Thread: copy limited number of records
Howdy:
Running PostgreSQL 7.2.1 on RedHat Linux 7.2.
I'm using copy to create a bunch of flat files with delimiters
and it's going okay. I've been asked, however, that the clients
don't actually want ALL of the data in the table; perhaps about
100 or so records for testing.
Is there a way to use limit while using the \copy command?
(e.g., \copy t_test_tbl to '/usr/local/home/admin/dev_tbls' using delimiters ',' limit 10)
I know the above doesn't work, but, perhaps there is a work around?
Thanks!
-X
Howabout using SELECT INTO ... LIMIT ... to select into a temporary table and then run COPY on it? Lee. Johnson, Shaunn writes: > Running PostgreSQL 7.2.1 on RedHat Linux 7.2. > > I'm using copy to create a bunch of flat files with delimiters > and it's going okay. I've been asked, however, that the clients > don't actually want ALL of the data in the table; perhaps about > 100 or so records for testing. > > Is there a way to use limit while using the \copy command? > (e.g., \copy t_test_tbl to '/usr/local/home/admin/dev_tbls' using delimiters > ',' limit 10) > > I know the above doesn't work, but, perhaps there is a work around? >
On Mon, 2002-11-04 at 15:02, Johnson, Shaunn wrote: > Howdy: > > Running PostgreSQL 7.2.1 on RedHat Linux 7.2. > > I'm using copy to create a bunch of flat files with delimiters > and it's going okay. I've been asked, however, that the clients > don't actually want ALL of the data in the table; perhaps about > 100 or so records for testing. > > Is there a way to use limit while using the \copy command? > (e.g., \copy t_test_tbl to '/usr/local/home/admin/dev_tbls' using delimiters > ',' limit 10) > > I know the above doesn't work, but, perhaps there is a work around? You can use Unix commands: head -100 /usr/local/home/admin/dev_tbls | psql -d your_db -c "COPY t_test_tbl FROM STDIN" -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight, UK http://www.lfix.co.uk/oliver GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C ======================================== "Lo, children are an heritage of the LORD; and the fruit of the womb is his reward." Psalms 127:3
SELECT * INTO t_test_table_out FROM t_test_table LIMIT 10; COPY t_test_table_out TO '/usr/local/home/admin/dev_tbls' USING DELIMITERS ','; DROP TABLE t_test_table_out; HTH, CG --- Oliver Elphick <olly@lfix.co.uk> wrote: > On Mon, 2002-11-04 at 15:02, Johnson, Shaunn wrote: > > Howdy: > > > > Running PostgreSQL 7.2.1 on RedHat Linux 7.2. > > > > I'm using copy to create a bunch of flat files with delimiters > > and it's going okay. I've been asked, however, that the clients > > don't actually want ALL of the data in the table; perhaps about > > 100 or so records for testing. > > > > Is there a way to use limit while using the \copy command? > > (e.g., \copy t_test_tbl to '/usr/local/home/admin/dev_tbls' using > delimiters > > ',' limit 10) > > > > I know the above doesn't work, but, perhaps there is a work around? > > You can use Unix commands: > > head -100 /usr/local/home/admin/dev_tbls | > psql -d your_db -c "COPY t_test_tbl FROM STDIN" > > -- > Oliver Elphick Oliver.Elphick@lfix.co.uk > Isle of Wight, UK > http://www.lfix.co.uk/oliver > GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C > ======================================== > "Lo, children are an heritage of the LORD; and the > fruit of the womb is his reward." Psalms 127:3 > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) __________________________________________________ Do you Yahoo!? HotJobs - Search new jobs daily now http://hotjobs.yahoo.com/