public inbox for [email protected]
help / color / mirror / Atom feedFrom: hubert depesz lubaczewski <[email protected]>
To: Nicolas Mitchell <[email protected]>
Cc: [email protected]
Subject: Re: Trigger function
Date: Tue, 27 Jul 2021 08:38:05 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
On Mon, Jul 26, 2021 at 03:17:12PM +0000, Nicolas Mitchell wrote:
> I am looking at whether functions can help me automate creating a new object
> when a new host is added.
>
> I can do this manually with the following code:
>
> WITH object_id AS
> (INSERT INTO public.object (type)
> VALUES (
> ( SELECT obtype.id
> FROM public.obtype
> WHERE obtype.name LIKE 'host'
> )
> )
> RETURNING id)
> INSERT INTO host (name, domain, object)
> VALUES ('gary', 1000001, (SELECT * FROM object_id));
>
> I have a number of questions but I would like to begin by asking whether
> this a candidate for a trigger function on table ‘host’, triggered before an
> insert?
*after* insert, not *before*.
But other than that yes.
If I might suggest:
https://www.depesz.com/2012/11/14/how-i-learned-to-stop-worrying-and-love-the-triggers/
depesz
view thread (11+ messages) latest in thread
reply
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Trigger function
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox