Trigger Function
I currently have this trigger and function to add a new row to my public users table whenever a new user signs up.
How do I also trigger a function that adds a row in the
folder
table with the name set to 'default' and the userId set to the new user that was just created?
My folder
table has the following columns: id, name, userId
Thank you!
13 Replies
I'm not sure what you're asking here? are you asking how to create another trigger function?
Hey @Zeph, I believe it'd be very similar:
Couple things to note:
- single quotes here used for a string literal - double quotes are used only to escape identifiers (like table name or row names)
- your public folder should have a default way to generate an
id
, so you shouldn't need to provide one on inserts@zackderose Thanks so much!
I tried it out but I get
database error saving new user
. This is an issue I've been facing whenever I try to create any other trigger other than the one in my original post. Any idea what could be the cause of it?interesting - is this error when you do this in the sql editor? Or when you insert?
When I try to sign up a new user.
You should not be using capital letters in Postgres for names of tables or columns unless forced to by a 3rd party application. You have to remember to always put them in double quotes "userId" when you use them in SQL.
@garyaustin ahh.. okay let me give that a shot(: Thank you!
ooh good to know
Yes I'm finding i didn't know sql as well as I thought I did lol
https://discord.com/channels/839993398554656828/885237287280070708/988097402059780098
Also when you get a 500 error, you can usually look at the Postgres logs right after and it will tell you what was wrong.
is the idea to tail the machine remotely @garyaustin or is there some way to see the logs via the ui?
@zackderose There is a postgres logs in the UI(:
oh nice - looks like it's not in local dev - but the db logs are accessible via docker here
@garyaustin I checked the logs and I'm got the following:
Any idea what could be causing this? My RLS is disabled.
I can confirm that it is the trigger that
create_folder_for_new_user
trigger that is causing the issue but I'm not sure why.
Without this trigger, the trigger that calls the handle_new_user
function works fine.