Re: How to give \COPY inside a function

From: John R Pierce <pierce(at)hogranch(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to give \COPY inside a function
Date: 2011-08-17 05:30:51
Message-ID: 4E4B520B.4080705@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 \COPY command at all! Could you please guide me briefly on how to use \COPY command for my usage to write the output into a .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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Siva Palanisamy 2011-08-17 05:33:04 How to write a psql command inside a function?
Previous Message Siva Palanisamy 2011-08-17 05:03:00 Re: How to give \COPY inside a function