BUG #6213: COPY does not work as expected in a plpgsql function - Mailing list pgsql-bugs

From Ramanujam
Subject BUG #6213: COPY does not work as expected in a plpgsql function
Date
Msg-id 201109190255.p8J2tAX0011023@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #6213: COPY does not work as expected in a plpgsql function  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      6213
Logged by:          Ramanujam
Email address:      innomotive@gmail.com
PostgreSQL version: 9.0
Operating system:   linux x86_64
Description:        COPY does not work as expected in a plpgsql function
Details:

A function like this:

CREATE OR REPLACE FUNCTION test(parm character varying(3)) RETURNS SETOF
integer AS
$BODY$

BEGIN
    COPY (SELECT $1) TO '/tmp/test.txt' CSV;
END;

$BODY$
LANGUAGE plpgsql VOLATILE COST 100 ROWS 100;

Throws an error:
NUM:42P02, DETAILS:there is no parameter $1

Substrituting $1 with parm gives this error:
NUM:42703, DETAILS:column "parm" does not exist

pgsql-bugs by date:

Previous
From: Robert Haas
Date:
Subject: Re: BUG #6205: ERROR: temporary tables cannot specify a schema name
Next
From: "yulin liu"
Date:
Subject: BUG #6214: can't change Column COLLATE