Does anyone know how to delcare and use a variable...
# sql
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 $$
  new_project_id uuid;
  new_project_id = uuid_generate_v4();
  -- insert into public.profiles (id, project) values (, ''); 
  -- insert into public.projects (id, type, name) values (new_project_id, 'PERSONAL', '...');
  -- insert into public.profiles_projects (profile_id, project_id) values (, new_project_id);
  return new;
$$ language plpgsql security definer;
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
. If you need to see errors, pgadmin is much better at giving hints as to what the problem is
you could declare as much as you want as long as the format as below
Copy code
new_project_id := uuid_generate_v4();
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