Обсуждение: PL/PgSQL composite parameter usage?

Поиск
Список
Период
Сортировка

PL/PgSQL composite parameter usage?

От
Patrick Higgins
Дата:
I read in the documentation (section 37.4.3 of the 7.4 docs) that
"Parameters to a function can be composite types," but when I try to
call such a function, I get an error. I've attached my test functions
below. Can anyone tell me what's wrong? I've tried the same function
using RECORD types, and it also does not work. This is using 7.4
compiled from source on x86 Linux.

test=> CREATE TABLE tablea (a int, b int, c int);
CREATE TABLE
test=>
test=> CREATE OR REPLACE FUNCTION funca() RETURNS INTEGER AS '
test'> DECLARE
test'>     v tablea;
test'> BEGIN
test'> v.a := 1;
test'> v.b := 2;
test'> v.c := 3;
test'>     PERFORM funcb(v);
test'>     RETURN NULL;
test'> END;
test'> ' LANGUAGE 'plpgsql';
CREATE FUNCTION
test=>
test=> CREATE OR REPLACE FUNCTION funcb(tablea) RETURNS INTEGER AS '
test'> BEGIN
test'>     INSERT INTO tablea (a, b, c) VALUES ($1.a, $1.b, $1.c);
test'>     RETURN NULL;
test'> END;
test'> ' LANGUAGE 'plpgsql';
CREATE FUNCTION
test=>
test=> SELECT funca();
ERROR:  column "v" does not exist
CONTEXT:  PL/pgSQL function "funca" line 7 at perform



Re: PL/PgSQL composite parameter usage?

От
Tom Lane
Дата:
Patrick Higgins <phiggins@brazen.net> writes:
> I read in the documentation (section 37.4.3 of the 7.4 docs) that
> "Parameters to a function can be composite types," but when I try to
> call such a function, I get an error.

This isn't really an issue of what a parameter can be, but a reflection
of plpgsql's rather limited ability to deal with composite-type
variables.  It doesn't know how to pass whole rows down to the SQL
engine, as it would need to do in your PERFORM:

> test'>     v tablea;

> test'>     PERFORM funcb(v);

This could probably get fixed if anyone was really motivated to do so.

            regards, tom lane