I added a trigger to the auth.users table on inse...
# sql
j
I added a trigger to the auth.users table on insert. But author_id is still empty whilst it should contain the
id
from the auth.users table?
Copy code
-- create function for adding user to default watchlist
CREATE OR REPLACE FUNCTION give_user_default_watchlist() RETURNS TRIGGER as
$$
  BEGIN
    insert into public.watchlists(author_id) VALUES (new.id);
    return new;
  END
$$ language plpgsql security definer;

--Use the function when auth.users gets an insert
drop trigger if exists default_user_watchlist on auth.users;
create trigger default_user_watchlist after insert on auth.users execute procedure give_user_default_watchlist();
j
if you're trying to insert a new row, then your trigger function should require the other columns to be specified as well right?
unless you've set a default for every other column?
j
This got fixed @User . There was a
for each
row in my original code
Copy code
-- create function for adding user to default watchlist
CREATE OR REPLACE FUNCTION give_user_default_watchlist() RETURNS TRIGGER as
$$
  BEGIN
    insert into public.watchlists (author_id) VALUES (new.id);
    return new;
  END;
$$ language plpgsql security definer;

--Use the function when auth.users gets an insert
drop trigger if exists default_user_watchlist on auth.users;
create trigger default_user_watchlist after insert on auth.users for each row execute function give_user_default_watchlist();
and that didn't work
thanks for your help, I appreciate your time