Обсуждение: PL/pgSQL triggers with parameters don't work

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

PL/pgSQL triggers with parameters don't work

От
pgsql-bugs@postgresql.org
Дата:
José María Fernández González (jmfernandez@cnb.uam.es) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
PL/pgSQL triggers with parameters don't work

Long Description
    The report is for PostgreSQL 7.1.2. When you create a trigger which calls a function with parameters, the system
linksagainst the function with the same name and no parameter, and if it doesn't exist it tells "function doesn't
exist".Tests have been made with PL/pgSQL-encoded functions. 

Sample Code
CREATE table a(
    b INTEGER,
    c TEXT
);

CREATE FUNCTION cascaya (INTEGER) RETURNS OPAQUE AS '
DECLARE
    value ALIAS FOR $1;
BEGIN
    IF value > 0
    THEN
        RAISE EXCEPTION ''Value: %'',value;
    END IF;
    return NULL;
END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER case1 BEFORE INSERT
ON a FOR EACH ROW
EXECUTE PROCEDURE cascaya(5);

ERROR:  CreateTrigger: function cascaya() does not exist

CREATE FUNCTION cascaya () RETURNS OPAQUE AS '
BEGIN
    return NULL;
END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER case2 BEFORE INSERT
ON a FOR EACH ROW
EXECUTE PROCEDURE cascaya(5);

select proname,pronargs,oid from pg_proc where proname='cascaya';

 proname | pronargs |   oid
---------+----------+---------
 cascaya |        0 | 1050555
 cascaya |        1 | 1050554

select tgname,tgfoid,tgnargs from pg_trigger where tgname='case2';

 tgname | tgfoid  | tgnargs
--------+---------+---------
 case2  | 1050555 |       1



No file was uploaded with this report

Re: PL/pgSQL triggers with parameters don't work

От
Stephan Szabo
Дата:
On Wed, 11 Jul 2001 pgsql-bugs@postgresql.org wrote:

> José María Fernández González (jmfernandez@cnb.uam.es) reports a bug
> with a severity of 2
> The lower the number the more severe it is.
>
> Short Description
> PL/pgSQL triggers with parameters don't work
>
> Long Description
>     The report is for PostgreSQL 7.1.2. When you create a trigger
> which calls a function with parameters, the system links against the
> function with the same name and no parameter, and if it doesn't exist
> it tells "function doesn't exist". Tests have been made with
> PL/pgSQL-encoded functions.

Trigger functions take their arguments in a different fashion.
They should be defined as taking no regular arguments and returning
opaque and it's something like TG_ARGS in plpgsql that the create
trigger time arguments are passed in.  I believe this is described in
the documentation.