Re: How to give \COPY inside a function

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to give \COPY inside a function
Date: 2011-08-16 15:14:09
Message-ID: 4E4A8941.8000406@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2011-08-16 15:44:14 Re: Using Postgresql as application server
Previous Message Siva Palanisamy 2011-08-16 15:07:08 How to give \COPY inside a function