pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Dump  and Query
5+ messages / 5 participants
[nested] [flat]

* Re: Dump  and Query
@ 2006-12-27 12:14  Andy Shellam (Mailing Lists) <andy.shellam-lists@mailnetwork.co.uk>
  parent: Enrico <scotty@linuxtime.it>
  2 siblings, 1 reply; 5+ messages in thread

From: Andy Shellam (Mailing Lists) @ 2006-12-27 12:14 UTC (permalink / raw)
  To: Enrico <scotty@linuxtime.it>; +Cc: pgsql-admin

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




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Dump and Query
@ 2006-12-27 12:18  Shoaib Mir <shoaibmir@gmail.com>
  parent: Enrico <scotty@linuxtime.it>
  2 siblings, 0 replies; 5+ messages in thread

From: Shoaib Mir @ 2006-12-27 12:18 UTC (permalink / raw)
  To: Enrico <scotty@linuxtime.it>; +Cc: pgsql-admin

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)

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
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Dump  and Query
@ 2006-12-27 13:05  Enrico <scotty@linuxtime.it>
  0 siblings, 3 replies; 5+ messages in thread

From: Enrico @ 2006-12-27 13:05 UTC (permalink / raw)
  To: pgsql-admin

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Dump  and Query
@ 2006-12-27 16:17  Bricklen Anderson <banderson@presinet.com>
  parent: Andy Shellam (Mailing Lists) <andy.shellam-lists@mailnetwork.co.uk>
  0 siblings, 0 replies; 5+ messages in thread

From: Bricklen Anderson @ 2006-12-27 16:17 UTC (permalink / raw)
  To: Andy Shellam (Mailing Lists) <andy.shellam-lists@mailnetwork.co.uk>; +Cc: pgsql-admin

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Dump  and Query
@ 2006-12-27 20:20  Bruno Wolff III <bruno@wolff.to>
  parent: Enrico <scotty@linuxtime.it>
  2 siblings, 0 replies; 5+ messages in thread

From: Bruno Wolff III @ 2006-12-27 20:20 UTC (permalink / raw)
  To: Enrico <scotty@linuxtime.it>; +Cc: pgsql-admin

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.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2006-12-27 20:20 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-12-27 13:05 Dump  and Query Enrico <scotty@linuxtime.it>
2006-12-27 12:14 ` Andy Shellam (Mailing Lists) <andy.shellam-lists@mailnetwork.co.uk>
2006-12-27 16:17   ` Bricklen Anderson <banderson@presinet.com>
2006-12-27 12:18 ` Re: Dump and Query Shoaib Mir <shoaibmir@gmail.com>
2006-12-27 20:20 ` Bruno Wolff III <bruno@wolff.to>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox