Thread: Redirecting output from a SELECT command

Redirecting output from a SELECT command

From
peter@vfemail.net
Date:
From a shell prompt in FreeBSD, I can use a command like:

    cat file.txt | mail email@domain.com

to e-mail the contents of a file somewhere.

Is it possible from a PostgreSQL pgsql> shell prompt to e-mail the results of a:

    select * from table;

command somewhere?

I'd like to share a printed copy of that output with someone, and there's no printer connected to the database server,
andI only have access to the database server from the console.   


-------------------------------------------------
This message sent via VFEmail.net
http://www.vfemail.net
$14.95 Lifetime accounts - 1GB disk, No bandwidth quotas!


Re: Redirecting output from a SELECT command

From
Andreas Kretschmer
Date:
peter@vfemail.net <peter@vfemail.net> wrote:

>
> >From a shell prompt in FreeBSD, I can use a command like:
>
>     cat file.txt | mail email@domain.com
>
> to e-mail the contents of a file somewhere.
>
> Is it possible from a PostgreSQL pgsql> shell prompt to e-mail the results of a:
>
>     select * from table;
>
> command somewhere?

Sure.

psql db_name -c "select * from table" | mail email@domain.com



Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: Redirecting output from a SELECT command

From
peter@vfemail.net
Date:
At 01:42 PM 11/11/2010, Andreas Kretschmer wrote:
>peter@vfemail.net <peter@vfemail.net> wrote:
>
>>
>> >From a shell prompt in FreeBSD, I can use a command like:
>>
>>     cat file.txt | mail email@domain.com
>>
>> to e-mail the contents of a file somewhere.
>>
>> Is it possible from a PostgreSQL pgsql> shell prompt to e-mail the results of a:
>>
>>     select * from table;
>>
>> command somewhere?
>
>Sure.
>
>psql db_name -c "select * from table" | mail email@domain.com

Super.  Thank you!


-------------------------------------------------
This message sent via VFEmail.net
http://www.vfemail.net
$14.95 Lifetime accounts - 1GB disk, No bandwidth quotas!


Re: Redirecting output from a SELECT command

From
Jasen Betts
Date:
On 2010-11-11, peter@vfemail.net <peter@vfemail.net> wrote:
>
> Frmail email@domain.comom a shell prompt in FreeBSD, I can use a command like:
>
>     cat file.txt | mail email@domain.com
>
> to e-mail the contents of a file somewhere.
>
> Is it possible from a PostgreSQL pgsql> shell prompt to e-mail the results of a:
>
>     select * from table;
>
> command somewhere?

yes.

-- open a pipe
\o | mail email@domain.com -s 'the database result'
-- run the query
select * from table;
-- close the pipe and cause delivery
\o

> I'd like to share a printed copy of that output with someone, and there's no printer connected to the database
server,and I only have access to the database server from the console.   

\o | lpr -H SERVER -P QUEUE

(eg into a ssh tunnel leading to printer or server on your lan)

--
⚂⚃ 100% natural