Обсуждение: Function problem.

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

Function problem.

От
"Geoff Ellis"
Дата:
I've got a tiny problem with how I want this function to work.

On and insert/delete from a table, I want to check to see if a field
contains a certain valule. If it does, not to insert or delete the record.
If it doesn't I want to go ahead and insert/delete the record.

Here's my function.

-- Function: users_upd_del()

CREATE FUNCTION users_upd_del() RETURNS int2 AS 'BEGIN

  IF ( NEW.username = ''emsroot'' ) THEN

    RAISE NOTICE ''Cannot REMOVE user  [ (%) ]'', NEW.username;

    RETURN NULL;

  END IF;

  RETURN 1;

END'  LANGUAGE 'plpgsql';


However, when this run I get the error

=== ERROR: fmgr_info: function 696542: cache lookup failed =====

I've tried to change the return type to opaque and remove the RETURN 1; But
if the condition isn't true then I don't have a return.

Can someone help me here, I've looked through the 7.3rc1 Docs shipped with
pgadmin and can't quite see what I'm after...

thanks

Geoff





Re: Function problem.

От
Tom Lane
Дата:
"Geoff Ellis" <geoff@metalogicplc.com> writes:
> === ERROR: fmgr_info: function 696542: cache lookup failed =====

This is on 7.3?  My first guess would have been that you deleted and
recreated the function without recreating the trigger that references
it.  But 7.3 should not let you do that.

> I've tried to change the return type to opaque and remove the RETURN 1; But
> if the condition isn't true then I don't have a return.

In an update trigger, you RETURN NEW in the normal case where you want
the update to proceed.

            regards, tom lane