I must be doing something wrong as I can't get thi...
# help
t
I must be doing something wrong as I can't get this trigger to work. My use case is I have a "profiles" table and an "articles" table. When a user updates the profiles table with a new user name, I want it to trigger an update on articles for the column "created_by". I keep getting a PATCH error with the message "column \"created_by\" does not exist" and I'm not sure why. My function to run on trigger is:
Copy code
begin
  UPDATE public.articles 
  SET created_by = public.getusername();
  RETURN created_by;
end;
return type trigger The getusername() function is:
Copy code
select username
from public.profiles
where id = auth.uid();
And returns text. I know this function works as it's the default value on the articles table on row insert, but not sure why it keeps erroring on update
g
I'm out of time, so can't really look deep or respond again tonight, but I think you want to return "new" on a trigger. And maybe even do new.created_by =,
But I just glanced and need to run, sorry...
t
Ah okay so the issue was I need to just return new. So final function is:
Copy code
begin
  UPDATE public.articles 
  SET created_by = public.getusername();
  RETURN new;
end;
Thanks for the help! I spent hours trying to figure out why
@User