0

I have two database say db1 and db2. And two tables user_auth_table in db1 and user_table in db2. Now I want to trigger a function which sync up few values in both tables for each new row or on each new insertion in user_auth_table.

I have tried to write on my own and creating trigger in db1. But the error says user_table doesn't exist. Which I know why I am getting this error. Any suggestion to target the tables outside the db ?

CREATE TRIGGER sync_user_table AFTER INSERT ON user_auth_table for each row execute procedure syncAndMaintainUsersTable()

create or replace function syncAndMaintainUsersTable()
returns trigger as
$BODY$
begin
if NEW.user_uuid<>OLD.user_uuid then
    insert into user_table values (NEW.user_uuid, CURRENT_TIMESTAMP, NEW.provider);
end if;
return new;
end;
$BODY$
language plpgsql;
1
  • Yes, it's the actual syntax – Lokesh Pandey Jun 15 '20 at 13:31
1

Usually the full qualified name of a db table is:

catalog.schema.table

If you want to insert some values into another table you should use this syntax:

insert into catalog.schema.table
values (..., ..., ...)
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.