Skip site navigation (1) Skip section navigation (2)

Re: SELECT to an external file

From: Mário Gamito <gamito(at)netual(dot)pt>
To: pgsql-general(at)postgresql(dot)org
Subject: SELECT to an external file
Date: 2004-08-24 17:08:26
Message-ID: 412B760A.8000800@netual.pt (view raw)
Hi,

How can i draw the results of a SELECT in to a file in the filesystem ?

Warm Regards,
Mário Gamito

From: Devrim GUNDUZ <devrim(at)gunduz(dot)org>
To: Mário Gamito <gamito(at)netual(dot)pt>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT to an external file
Date: 2004-08-24 17:12:39
Message-ID: Pine.LNX.4.44.0408242010540.3666-100000@emo.org.tr (view raw)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi,

On Tue, 24 Aug 2004, [ISO-8859-1] Mário Gamito wrote:

> How can i draw the results of a SELECT in to a file in the filesystem ?

Use \o:

test=# \o testfile
test=# SELECT * from mytable;
test=#

All the output is redirected to testfile.

Regards,
- -- 
Devrim GUNDUZ	       
devrim~gunduz.org				devrim.gunduz~linux.org.tr 
			http://www.tdmsoft.com
			http://www.gunduz.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFBK3cJtl86P3SPfQ4RAqXlAJ4rpEmebsqRM5f6eWLX6DKMdlFZ8QCgvzHk
bSMZ2kr9s9brM6U6Bn27jJs=
=CREY
-----END PGP SIGNATURE-----


From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Mário Gamito <gamito(at)netual(dot)pt>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT to an external file
Date: 2004-08-24 17:13:59
Message-ID: 1093367639.15248.11.camel@linda (view raw)
On Tue, 2004-08-24 at 18:08, Mário Gamito wrote:
> Hi,
> 
> How can i draw the results of a SELECT in to a file in the filesystem ?

Using psql:

  1.  \o /path/to/file
      SELECT ... ;
      \o

  2. psql -d my_database -c "SELECT ... " >/path/to/file

-- 
Oliver Elphick                                          olly(at)lfix(dot)co(dot)uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA  92C8 39E7 280E 3631 3F0E  1EC0 5664 7A2F A543 10EA
                 ========================================
     "I saw in the night visions, and, behold, one like the 
      Son of man came with the clouds of heaven, and came to
      the Ancient of days, and they brought him near before 
      him. And there was given him dominion, and glory, and 
      a kingdom, that all people, nations, and languages, 
      should serve him; his dominion is an everlasting 
      dominion, which shall not pass away, and his kingdom 
      that which shall not be destroyed."     
                                    Daniel 7:13,14


From: Mário Gamito <gamito(at)netual(dot)pt>
To: olly(at)lfix(dot)co(dot)uk
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT to an external file
Date: 2004-08-24 17:20:45
Message-ID: 412B78ED.8020702@netual.pt (view raw)
Hi,

First of all, thank you for your answers.

Look at this file output:

                                               url_negado
------------------------------------------------------------------------------------------------------
  www.startux.org
  www.hotmail.com
  www.blabla.com
(3 rows)


Is there a way to postgres not print the 1st, 2nd and last line ?
I need a list just with URLs.

Thank you in advance.

Warm Regards,
Mário Gamito

Oliver Elphick wrote:
> On Tue, 2004-08-24 at 18:08, Mário Gamito wrote:
> 
>>Hi,
>>
>>How can i draw the results of a SELECT in to a file in the filesystem ?
> 
> 
> Using psql:
> 
>   1.  \o /path/to/file
>       SELECT ... ;
>       \o
> 
>   2. psql -d my_database -c "SELECT ... " >/path/to/file
> 

From: Jeff Amiel <jamiel(at)istreamimaging(dot)com>
To: Mário Gamito <gamito(at)netual(dot)pt>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT to an external file
Date: 2004-08-24 17:22:12
Message-ID: 412B7944.5060705@istreamimaging.com (view raw)
psql -c "select * from table" dbname >filename.txt



Mário Gamito wrote:

> Hi,
>
> How can i draw the results of a SELECT in to a file in the filesystem ?
>
> Warm Regards,
> Mário Gamito
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
>


From: Jeff Amiel <jamiel(at)istreamimaging(dot)com>
To: Mário Gamito <gamito(at)netual(dot)pt>
Cc: olly(at)lfix(dot)co(dot)uk, pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT to an external file
Date: 2004-08-24 17:35:49
Message-ID: 412B7C75.6030105@istreamimaging.com (view raw)
use the psql -t option

Jeff

Mário Gamito wrote:

> Hi,
>
> First of all, thank you for your answers.
>
> Look at this file output:
>
>                                               url_negado
> ------------------------------------------------------------------------------------------------------ 
>
>  www.startux.org
>  www.hotmail.com
>  www.blabla.com
> (3 rows)
>
>
> Is there a way to postgres not print the 1st, 2nd and last line ?
> I need a list just with URLs.
>
> Thank you in advance.
>
> Warm Regards,
> Mário Gamito
>
> Oliver Elphick wrote:
>
>> On Tue, 2004-08-24 at 18:08, Mário Gamito wrote:
>>
>>> Hi,
>>>
>>> How can i draw the results of a SELECT in to a file in the filesystem ?
>>
>>
>>
>> Using psql:
>>
>>   1.  \o /path/to/file
>>       SELECT ... ;
>>       \o
>>
>>   2. psql -d my_database -c "SELECT ... " >/path/to/file
>>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>



Privacy Policy | About PostgreSQL
Copyright © 1996-2013 The PostgreSQL Global Development Group