From: Adrian Klaver <adrian.klaver@aklaver.com>
To: FOUTE K. Jaurès <jauresfoute@gmail.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: Call a Normal function inside a Trigger Function
Date: Sun, 16 Apr 2023 12:13:12 -0700
Message-ID: <a7e9cf7a-ae6e-e3c3-4c72-d6adfc523967@aklaver.com> (raw)
In-Reply-To: <CAHQ1jfedkxUzF4YqF3_bgX99zVem+tVCf20--h2dBm7hVgXbrg@mail.gmail.com>
References: <CAHQ1jfdZWH_UyMEj-x2yMm4GfLe6R=Wr=jgEh0GgKXyp249PWg@mail.gmail.com>
<CAFj8pRDoX1zEVD_-Xz=ZgEQubdaJc9nTwUM0TFtFrR0xLzYc9g@mail.gmail.com>
<CAHQ1jfedkxUzF4YqF3_bgX99zVem+tVCf20--h2dBm7hVgXbrg@mail.gmail.com>
On 4/16/23 11:47, FOUTE K. Jaurès wrote:
> Can I have an example please? Or a link
create table trg_test (id integer, fld_1 varchar, fld_2 boolean);
CREATE OR REPLACE FUNCTION public.child_fnc(token character varying)
RETURNS void
LANGUAGE plpgsql
AS $function$
BEGIN
IF token = 'yes' THEN
RAISE NOTICE 'Child';
END IF;
END;
$function$
;
CREATE OR REPLACE FUNCTION public.parent_fnc()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
RAISE NOTICE 'Id is %', NEW.id;
RAISE NOTICE 'Fld_1 is %', NEW.fld_1;
RAISE NOTICE 'Parent';
PERFORM child_fnc('yes');
RETURN NEW;
END;
$function$
;
create trigger test_trg before insert on trg_test for each row execute
function parent_fnc();
insert into trg_test values (1, 'dog', 'f');
NOTICE: Id is 1
NOTICE: Fld_1 is dog
NOTICE: Parent
NOTICE: Child
INSERT 0 1
>
> On Sun, 16 Apr 2023, 17:08 Pavel Stehule, <pavel.stehule@gmail.com
> <mailto:pavel.stehule@gmail.com>> wrote:
>
> Hi
>
>
> ne 16. 4. 2023 v 16:15 odesílatel FOUTE K. Jaurès
> <jauresfoute@gmail.com <mailto:jauresfoute@gmail.com>> napsal:
>
> Hello,
>
> Is it possible to call a function inside a trigger function ?
> Any idea or link are welcome. Thanks in advance
>
>
> sure, there is not any limit.
>
> Regards
>
> Pavel
>
>
> Best Regards
> --
> Jaurès FOUTE
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, jauresfoute@gmail.com, pavel.stehule@gmail.com
Subject: Re: Call a Normal function inside a Trigger Function
In-Reply-To: <a7e9cf7a-ae6e-e3c3-4c72-d6adfc523967@aklaver.com>
References: <CAHQ1jfdZWH_UyMEj-x2yMm4GfLe6R=Wr=jgEh0GgKXyp249PWg@mail.gmail.com> <CAFj8pRDoX1zEVD_-Xz=ZgEQubdaJc9nTwUM0TFtFrR0xLzYc9g@mail.gmail.com> <CAHQ1jfedkxUzF4YqF3_bgX99zVem+tVCf20--h2dBm7hVgXbrg@mail.gmail.com> <a7e9cf7a-ae6e-e3c3-4c72-d6adfc523967@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox