Re: How to give \COPY inside a function - Mailing list pgsql-general

From John R Pierce
Subject Re: How to give \COPY inside a function
Date
Msg-id 4E4B520B.4080705@hogranch.com
Whole thread Raw
In response to Re: How to give \COPY inside a function  (Siva Palanisamy <siva_p@hcl.com>)
List pgsql-general
On 08/16/11 10:03 PM, Siva Palanisamy wrote:
> Hi John,
>
> I would like to add that I was not given the super user privilege to perform COPY command. If so, I wouldn't see
\COPYcommand at all! Could you please guide me briefly on how to use \COPY command for my usage to write the output
intoa .CSV file inside a function? 

a postgres function can not write a file, but it can execute a COPY ....
TO STDOUT ...; without superuser privilege.

your invoking application program would use whatever function in its
Postgres binding to read this 'stdout' data (its not really stdout),
like in C/C++ with libpq.so, you would use PQgetCopyData
http://www.postgresql.org/docs/current/static/libpq-copy.html#LIBPQ-COPY-RECEIVE
to receive this data stream, which you would write to a file via your
application




--
john r pierce                            N 37, W 122
santa cruz ca                         mid-left coast


pgsql-general by date:

Previous
From: Siva Palanisamy
Date:
Subject: Re: How to give \COPY inside a function
Next
From: Siva Palanisamy
Date:
Subject: How to write a psql command inside a function?