Does anyone know how to delcare and use a variable...
# sql
e
Does anyone know how to delcare and use a variable in a trigger - this is erroring:
Copy code
create or replace function public.create_project_on_new_user() 
returns trigger as $$
declare
  new_project_id uuid;
begin
  new_project_id = uuid_generate_v4();
  -- insert into public.profiles (id, project) values (new.id, ''); 
  -- insert into public.projects (id, type, name) values (new_project_id, 'PERSONAL', '...');
  -- insert into public.profiles_projects (profile_id, project_id) values (new.id, new_project_id);
  return new;
end;
$$ language plpgsql security definer;
s
You can probably drop the declare and the line below it. Alternatively, you can pass args into your function:
public.create_project_on_new_user(new_project_id uuid DEFAULT uuid_generate_v4())
. You might need to specify
extensions.uuid_generate_v4()
. If you need to see errors, pgadmin is much better at giving hints as to what the problem is
k
you could declare as much as you want as long as the format as below
Copy code
new_project_id := uuid_generate_v4();
e
Thanks all. Figured it out. I had to enable the extension with
create extension if not exists "uuid-ossp";
-
Was able to see the error in the Authentication logs, since it happens on user creation