1

I had two tables table1 and table2.

table1 has three entries - id primary key, fd foreign key(table2), val_t1

table2 has 2 entries - fd primary key, val_t2

If val_t1 of any row in the table1 is updated, it should trigger a function with the corresponding value of fd field as an argument. This fd should be used in the trigger function to get the corresponding val_t2 from the table2.

I have read about TG_ARGV but unable to use it in the trigger.

1 Answer 1

2

You do not need arguments, the value is in the new record, example:

create or replace function trigger_on_table1()
returns trigger language plpgsql as $$
declare
    val text;
begin
    select val_t2 into val
    from table2
    where fd = new.fd;
    raise notice '%', val;
    return new;
end;
$$
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.