https://supabase.com/ logo
create profile for new user trigger
r

Revathar

05/25/2023, 12:52 PM
This is my first time messing with triggers and functions, I wanted to have in my profiles table additional information that the user provide in the registration form, so I copied a simple function and created a trigger on auth after insert, "begin insert into public.profiles (id) values (new.id); return new; end;" But I'm getting an error: "failed to close prepared statement: ERROR: current transaction is aborted, commands ignored until end of transaction block (SQLSTATE 25P02): ERROR: column \"id\" is of type bigint but expression is of type uuid (SQLSTATE 42804)" Shouldn't new.id be of the correct type already? This line is copied from https://supabase.com/docs/guides/auth/managing-user-data so it should work, similar line works in another project I've seen and no one is getting such an error. I must've skipped an important step I guess? I cant fix it and I'd be very thankful for providing any direction in solving this problem.
g

garyaustin

05/25/2023, 1:14 PM
Is your profile id column bigint or UUID?
r

Revathar

05/25/2023, 1:15 PM
int8
g

garyaustin

05/25/2023, 1:16 PM
And user id is UUID
r

Revathar

05/25/2023, 1:16 PM
Yes
g

garyaustin

05/25/2023, 1:17 PM
That is your error
Your id column in profiles has to match the type coming from auth.users, which is UUID
OR at least you need a column in profiles that is UUID like user_id to write that to.
From the guide you linked.

https://cdn.discordapp.com/attachments/1111275647826939914/1111282400790593618/image.png

r

Revathar

05/25/2023, 1:24 PM
Thank you for answering already, but I can't change id table type, I'm getting failed to update pg.columns with the given ID: cannot cast type bigint to uuid even though the the whole profiles table is empty
Should I just delete original profiles and create it from scratch?
g

garyaustin

05/25/2023, 1:27 PM
Yeah postgres won't change bigint to uuid even empty. Or you can have a new column be the UUID column and still have an int primary key.
r

Revathar

05/25/2023, 1:29 PM
Allright, thank you very much for your time helping me, I really appreciate it