'missing parameter $1' for sql or pl/pgsql COPY - Mailing list pgsql-bugs

From Merlin Moncure
Subject 'missing parameter $1' for sql or pl/pgsql COPY
Date
Msg-id b42b73150909161302y3564dc4am28701b4898366f6@mail.gmail.com
Whole thread Raw
List pgsql-bugs
The following functions fail:

create or replace function docopy(int[]) returns int as
$$
  copy (select unnest($1)) to stdout;
  select 0;
$$ language sql;
ERROR:  there is no parameter $1

create or replace function docopy(int[]) returns int as
$$
begin
      copy (select unnest($1)) to stdout;
end;
$$ language plpgsql;
ERROR:  SPI_execute_plan failed executing query "copy (select unnest(
$1 )) to stdout": SPI_ERROR_COPY

this error is expected i guess, plpgsql doesn't support copy to stdout.

create or replace function docopy(_stuff int[]) returns int as
$$
begin
      copy (select unnest(_stuff)) to '/tmp/scratch';
end;
$$ language plpgsql;
ERROR:  there is no parameter $1

Also, copy does not allow variable substitution for the destination
file.  Dynamic sql is one work around, but EXECUTE USING does not
work:

create or replace function docopy(_stuff int[]) returns int as
$$
begin
      execute 'copy (select unnest($1)) to ''/tmp/scratch''' using _stuff;
end;
$$ language plpgsql;
ERROR:  there is no parameter $1

merlin

pgsql-bugs by date:

Previous
From: Jeff Davis
Date:
Subject: Re: strange bug with gist over box and circle
Next
From: Robert Haas
Date:
Subject: Re: BUG #5059: Planner ignores estimates when planning an IN () subquery