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;
-
Yes, it's the actual syntaxLokesh Pandey– Lokesh Pandey2020年06月15日 13:31:13 +00:00Commented Jun 15, 2020 at 13:31
1 Answer 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 (..., ..., ...)
-
Thank you, this worked.Lokesh Pandey– Lokesh Pandey2020年06月20日 13:35:08 +00:00Commented Jun 20, 2020 at 13:35