pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6213: COPY does not work as expected in a plpgsql function
5+ messages / 3 participants
[nested] [flat]

* BUG #6213: COPY does not work as expected in a plpgsql function
@ 2011-09-19 02:55 Ramanujam <innomotive@gmail.com>
  2011-09-26 00:57 ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Ramanujam @ 2011-09-19 02:55 UTC (permalink / raw)
  To: 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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6213: COPY does not work as expected in a plpgsql function
  2011-09-19 02:55 BUG #6213: COPY does not work as expected in a plpgsql function Ramanujam <innomotive@gmail.com>
@ 2011-09-26 00:57 ` Robert Haas <robertmhaas@gmail.com>
  2011-09-26 04:45   ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Ramanujam <innomotive@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Robert Haas @ 2011-09-26 00:57 UTC (permalink / raw)
  To: Ramanujam <innomotive@gmail.com>; +Cc: pgsql-bugs

On Sun, Sep 18, 2011 at 10:55 PM, Ramanujam <innomotive@gmail.com> wrote:
> 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

Does it work if you use EXECUTE?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6213: COPY does not work as expected in a plpgsql function
  2011-09-19 02:55 BUG #6213: COPY does not work as expected in a plpgsql function Ramanujam <innomotive@gmail.com>
  2011-09-26 00:57 ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Robert Haas <robertmhaas@gmail.com>
@ 2011-09-26 04:45   ` Ramanujam <innomotive@gmail.com>
  2011-09-26 13:40     ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Ramanujam @ 2011-09-26 04:45 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-bugs

On Mon, Sep 26, 2011 at 9:57 AM, Robert Haas <robertmhaas@gmail.com> wrote:
> Does it work if you use EXECUTE?

Apologies to have not included the list when I replied to Pavel.
Re-writing it as a dynamic sql stmt indeed works. Sorry for the noise.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6213: COPY does not work as expected in a plpgsql function
  2011-09-19 02:55 BUG #6213: COPY does not work as expected in a plpgsql function Ramanujam <innomotive@gmail.com>
  2011-09-26 00:57 ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Robert Haas <robertmhaas@gmail.com>
  2011-09-26 04:45   ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Ramanujam <innomotive@gmail.com>
@ 2011-09-26 13:40     ` Robert Haas <robertmhaas@gmail.com>
  2011-09-26 14:33       ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Robert Haas @ 2011-09-26 13:40 UTC (permalink / raw)
  To: Ramanujam <innomotive@gmail.com>; +Cc: pgsql-bugs

On Mon, Sep 26, 2011 at 12:45 AM, Ramanujam <innomotive@gmail.com> wrote:
> On Mon, Sep 26, 2011 at 9:57 AM, Robert Haas <robertmhaas@gmail.com> wrote:
>> Does it work if you use EXECUTE?
>
> Apologies to have not included the list when I replied to Pavel.
> Re-writing it as a dynamic sql stmt indeed works. Sorry for the noise.

Ah, OK.  No problem.

It would actually be nice if worked even without that, but I'm not
sure what would be involved in making that happen.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6213: COPY does not work as expected in a plpgsql function
  2011-09-19 02:55 BUG #6213: COPY does not work as expected in a plpgsql function Ramanujam <innomotive@gmail.com>
  2011-09-26 00:57 ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Robert Haas <robertmhaas@gmail.com>
  2011-09-26 04:45   ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Ramanujam <innomotive@gmail.com>
  2011-09-26 13:40     ` Re: BUG #6213: COPY does not work as expected in a plpgsql function Robert Haas <robertmhaas@gmail.com>
@ 2011-09-26 14:33       ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2011-09-26 14:33 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Ramanujam <innomotive@gmail.com>; pgsql-bugs

Robert Haas <robertmhaas@gmail.com> writes:
> It would actually be nice if worked even without that, but I'm not
> sure what would be involved in making that happen.

I've been too busy to look at this in detail, but I imagine the issue is
failure to pass parameters down from the ProcessUtility call to COPY
into the parsing/execution of the sub-SELECT.  It might be relatively
straightforward to fix, or then again it might not.  The parsing end of
it could quite likely be harder than the execution end.  We've
surmounted similar issues in places like EXPLAIN, though.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2011-09-26 14:33 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-19 02:55 BUG #6213: COPY does not work as expected in a plpgsql function Ramanujam <innomotive@gmail.com>
2011-09-26 00:57 ` Robert Haas <robertmhaas@gmail.com>
2011-09-26 04:45   ` Ramanujam <innomotive@gmail.com>
2011-09-26 13:40     ` Robert Haas <robertmhaas@gmail.com>
2011-09-26 14:33       ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox