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 4E4A8941.8000406@hogranch.com
Whole thread Raw
In response to How to give \COPY inside a function  (Siva Palanisamy <siva_p@hcl.com>)
Responses Re: How to give \COPY inside a function
List pgsql-general
On 08/16/11 8:07 AM, Siva Palanisamy wrote:
>
> I want to \COPY over COPY command as I am not running as a super/admin
> user. How to add \COPY command inside a function.
>
> The following statement inside a function throws error.
>
> \COPY xsa.export_table TO 'export.csv' DELIMITERS ',' CSV HEADER
>
> Errors are throwing at “\COPY” and no semi-colon at the end of the
> line. Please guide me.
>

\COPY is a psql metacommand, not a proper SQL command, its translated to
a SQL COPY command. you can't use \ commands in functions, so you'll
need to recode that as a COPY ... TO STDOUT ...; and recieve the stdout
stream and write it to your file (which is what the \COPY command is doing).



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



pgsql-general by date:

Previous
From: Siva Palanisamy
Date:
Subject: How to give \COPY inside a function
Next
From: Scott Marlowe
Date:
Subject: Re: [ADMIN] Using Postgresql as application server