Thread: Dump and Query
Is there any way to make a dump from a query? For example if my query is: select field1,field2 from table Does it exist a shell command like pg_dump --QUERY myquery -f myfile? Have a nice day Enrico -- If Bill Gates had a penny for everytime Windows crashed,he'd be a multi-billionaire by now .......oh look, he already is!!!! scotty@linuxtime.it - Skype:sscotty71 http://www.linuxtime.it/enricopirozzi
Hi Enrico, The following command will get you a text file of your result-set: # echo "SELECT customer_id, first_name, sur_name FROM users;"|/usr/local/pgsql/bin/psql -U [username] -d [database] > myfile.txt # cat myfile.txt customer_id | first_name | sur_name -------------+------------+---------- CUS0000002 | Andy | Shellam Or you can dump a specific table: # /usr/local/pgsql/bin/pg_dump --table=[tablename] [database] Regards, Andy. Enrico wrote: > Is there any way to make a dump from a query? > > For example if my query is: > > select field1,field2 from table > > Does it exist a shell command like pg_dump --QUERY myquery -f myfile? > > Have a nice day > Enrico > > -- Andy Shellam NetServe Support Team the Mail Network "an alternative in a standardised world" p: +44 (0) 121 288 0832/0839 m: +44 (0) 7818 000834
You can use the COPY (http://www.postgresql.org/docs/current/static/sql-copy.html) command for doing so....
An example will be -->
COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/usr1/proj/bray/sql/a_list_countries.copy';
---------------------
Shoaib Mir
EnterpriseDB (www.enterprisedb.com )
An example will be -->
COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/usr1/proj/bray/sql/a_list_countries.copy';
---------------------
Shoaib Mir
EnterpriseDB (www.enterprisedb.com )
On 12/27/06, Enrico <scotty@linuxtime.it> wrote:
Is there any way to make a dump from a query?
For example if my query is:
select field1,field2 from table
Does it exist a shell command like pg_dump --QUERY myquery -f myfile?
Have a nice day
Enrico
--
If Bill Gates had a penny for everytime Windows crashed,he'd be a multi-billionaire by now .......oh look, he already is !!!!
scotty@linuxtime.it - Skype:sscotty71
http://www.linuxtime.it/enricopirozzi
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Andy Shellam (Mailing Lists) wrote: > Hi Enrico, > > The following command will get you a text file of your result-set: > > # echo "SELECT customer_id, first_name, sur_name FROM > users;"|/usr/local/pgsql/bin/psql -U [username] -d [database] > myfile.txt > # cat myfile.txt Alternative version: psql -d <your dbname> -c "SELECT customer_id, first_name, sur_name FROM users" -o myfile.txt
On Wed, Dec 27, 2006 at 14:05:30 +0100, Enrico <scotty@linuxtime.it> wrote: > Is there any way to make a dump from a query? > > For example if my query is: > > select field1,field2 from table > > Does it exist a shell command like pg_dump --QUERY myquery -f myfile? In 8.2 you can use a query with the COPY command. Depending on what you are really doing, that might be a solution for you.