Re: Trigger Question - Mailing list pgsql-general

From Thomas Braad Toft
Subject Re: Trigger Question
Date
Msg-id 41DC64A0.10702@magicx.dk
Whole thread Raw
In response to Re: Trigger Question  (Terry Lee Tucker <terry@esc1.com>)
List pgsql-general
Terry Lee Tucker wrote:
> 1) INSERT INTO logs (carr_code, ..., ..., ...)  VALUES('ABCDEFG', ..., ...);
>     logs is table A in my question
>
> 2) logs_insert fires (This is a AFTER INSERT trigger)
>
> 3) in this trigger, I need to do the following:
>     update avlds set carr_code = new.carr_code where avlds.recid = ??;
>     avlds is table B in my question
>     The questions marks indicate the first piece of data that I want to
> dynamically pass to the trigger.
>
> 4) in the same trigger:
>     update tract set order_num = avlds.order_num where tract.recid = ??;
>     tract is table C in my question
>     The question marks refer to the second piece of data that I want to pass
> dynamically into the trigger.
>
> In other terms, when the user creates a logs record that assigns a truck to a
> load, I need to update specific rows in two other tables, avlds, and tract. I
> was wanting to do this from the trigger level, but I will need the unique
> serial key of each of the existing records in avlds and tract. These two keys
> comprise the "dynamic" part of the question. I was just wondering if there is
> some way of passing dynamic data into a trigger. I don't believe there is,
> but I thought I would ask.

I cannot figure out if you are supposed to use the same value as ??, but
I believe I would just create a function (which takes parameters) and
then call that from the logs_insert trigger. That way I believe you have
a much better control of the flow of your updates.

Hope that helps.

--
Thomas Braad Toft

pgsql-general by date:

Previous
From: MargaretGillon@chromalloy.com
Date:
Subject: SELECT WHERE NOT, is not working
Next
From: Alex Turner
Date:
Subject: Re: Trigger Question