Re: Trigger won't accept function (Please Help)

From: Jörg Wallerich <ib14-3(at)cs(dot)uni-sb(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Trigger won't accept function (Please Help)
Date: 2001-05-03 07:13:40
Message-ID: 3AF10524.F5F45076@cs.uni-sb.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi,

triggers call their registered functions always using the parameter-less
version. For Postgres, func() and func(text) are two entirely different
things! Also, trigger functions get an implicit set of parameters, like
NEW etc. (see documentation).

IMHO, this should be done as follows:

CREATE FUNCTION insert_default() RETURNS OPAQUE AS '
BEGIN
NEW.id_author_last_mod = NEW.id_author;
return NEW;
END;'
LANGUAGE 'plpgsql';

CREATE TRIGGER "iep_district_insert" BEFORE INSERT ON "iep_district"
FOR EACH ROW EXECUTE PROCEDURE insert_default();

J.W.

Micah Woods wrote:
>
> I've created a plpgsql function that takes 2 args as follows:
>
> CREATE FUNCTION insert_default(text,text) RETURNS OPAQUE AS 'BEGIN
> new.$1; RETURN new; END;' LANGUAGE 'plpgsql';
>
> When I try to reference this function when creating a trigger:
>
> CREATE TRIGGER "iep_district_insert" BEFORE INSERT ON "iep_district" FOR
> EACH ROW EXECUTE PROCEDURE insert_default('id_author','id_author_last_mod');
>
> I get this error: PostgreSQL said: ERROR: CreateTrigger: function
> insert_default() does not exist
>
> Questions:
>
> 1. I can ONLY reference functions in triggers that have NO args, any
> function (like above example) that takes 1 or more args always gets the does
> not exist error.
>
> 2. I'm new to postgres, perhaps there's a better way have the default value
> of a field be that of another field??
>
> Thanks for any help,
>
> Micah
> --
> Micah Woods
> Woods/IT LLC
> 2214 Waite Ave.
> Kalamazoo, MI 49008
>
> v: 616 349-1175
> f: 877 349-4929 (toll free)
> e: micah(at)woods-it(dot)com
> w: http://www.woods-it.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bart Lateur 2001-05-03 07:15:01 Re: [MacPerl] Perl Scope problem
Previous Message Justin Clift 2001-05-03 07:03:11 Daylight savings