Обсуждение: function return type for triggers in postgresql 8.0 rc2

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

function return type for triggers in postgresql 8.0 rc2

От
"PEDRO LOPEZ"
Дата:
I am porting an existing database to postgresql and am translating some
triggers.
I have the following objects:

A table named 'currentstatus'

a function which I orignally defined as:

CREATE OR REPLACE FUNCTION "CurrentStatus_DTrigx"() RETURNS opaque AS
$BODY$
    Begin
        if (select COUNT(*) FROM deleted, Stations WHERE deleted.CurrentStatusCode =
Stations.CurrentStatusCode) > 0 then
            RAISE EXCEPTION 'RAISERROR(778501, 16, 1)';
            ROLLBACK TRANSACTION;
        end if;
          END    $BODY$
LANGUAGE 'plpgsql' VOLATILE;

a trigger I defined as:
create trigger csd before delete on currentstatus for each row
execute procedure public.CurrentStatus_DTrig()

after struggling with 'function not defined errors', and unable to see what
was wrong I redefined the function as:

CREATE OR REPLACE FUNCTION currentstatus_dtrig() RETURNS opaque AS
$BODY$
    Begin
        if (select COUNT(*) FROM deleted, Stations WHERE deleted.CurrentStatusCode =
Stations.CurrentStatusCode) > 0 then
            RAISE EXCEPTION 'RAISERROR(778501, 16, 1)';
            ROLLBACK TRANSACTION;
        end if;
          END    $BODY$
LANGUAGE 'plpgsql' VOLATILE;

and got the message to the effect of 'redefining return type as trigger', and
the following function was created:
-- Function: currentstatus_dtrig()

-- DROP FUNCTION currentstatus_dtrig();

CREATE OR REPLACE FUNCTION currentstatus_dtrig()
   RETURNS "trigger" AS
$BODY$
    Begin
        if (select COUNT(*) FROM deleted, Stations WHERE deleted.CurrentStatusCode =
Stations.CurrentStatusCode) > 0 then
            RAISE EXCEPTION 'RAISERROR(778501, 16, 1)';
            ROLLBACK TRANSACTION;
        end if;
          END    $BODY$
   LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION currentstatus_dtrig() OWNER TO postgres;
GRANT EXECUTE ON FUNCTION currentstatus_dtrig() TO public;
GRANT EXECUTE ON FUNCTION currentstatus_dtrig() TO postgres;


This is strange, AFAICT I followed the documentation setting up the trigger
and functions (correct parameter signature and return type). Did I do
something wrong or is this a RC2 issue?

Thanks,
Pedro Lopez

Re: function return type for triggers in postgresql 8.0 rc2

От
Tom Lane
Дата:
"PEDRO LOPEZ" <p.lopez@bresnan.net> writes:
> after struggling with 'function not defined errors', and unable to see what
> was wrong I redefined the function as:

> CREATE OR REPLACE FUNCTION currentstatus_dtrig() RETURNS opaque AS
> ...

> and got the message to the effect of 'redefining return type as trigger',

Yup.

> This is strange, AFAICT I followed the documentation setting up the trigger
> and functions (correct parameter signature and return type).

It's been a long time (at least since 7.3) since the documentation
recommended using OPAQUE for anything.

            regards, tom lane