Re: pg_sample - Mailing list pgsql-general

From Greg Sabino Mullane
Subject Re: pg_sample
Date
Msg-id f7ca973dc47a6d83bc48a8f78f7d0987@biglumber.com
Whole thread Raw
In response to pg_sample  (Patrick B <patrickbakerbr@gmail.com>)
Responses Re: pg_sample  (Charles Clavadetscher <clavadetscher@swisspug.org>)
List pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160


Patrick B <patrickbakerbr@gmail.com> writes:
...
> However, this new database test server doesn't need to have all the data. I
> would like to have only the first 100 rows(example) of each table in my
> database.
...

This should do what you ask.

If the order does not matter, leave out the ORDER BY.

This assumes everything of interest is in the public schema.

$ createdb testdb
$ pg_dump realdb --schema-only | psql -q testdb
$ psql realdb

psql> \o dump.some.rows.sh
psql> select format($$psql realdb -c 'COPY (select * from %I order by 1 limit %s) TO STDOUT' | psql testdb -c 'COPY %I
FROMSTDIN' $$, table_name, 100, table_name) 
      from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE';
psql> \q

$ sh dump.some.rows.sh

- --
Greg Sabino Mullane greg@turnstep.com
End Point Corporation http://www.endpoint.com/
PGP Key: 0x14964AC8 201610182256
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAlgG4NkACgkQvJuQZxSWSsge4ACePhBOBtBFnGNxXt5qpY7X+w3o
d04AoKTzAgxcaqy8qfIE0LPuzG9x0KIU
=sS+m
-----END PGP SIGNATURE-----




pgsql-general by date:

Previous
From: Melvin Davidson
Date:
Subject: Re: pg_sample
Next
From: Charles Clavadetscher
Date:
Subject: Re: pg_sample