RPC insert into a table with uuid
# sql
o
RPC insert into a table with uuid
I'm trying to insert into a table from client passing the user_id and getting this error
Copy code
js
  message: 'column "user_id" is of type uuid but expression is of type text',
  code: '42804',
  details: null,
  hint: 'You will need to rewrite or cast the expression.'
my function
Copy code
sql
begin
  INSERT INTO public.payment(user_id)
    VALUES (user_id)
  INSERT INTO public.booking(event_url)
    VALUES (event_url);
    return id;
end;
my rpc call
Copy code
js
const { data, error } = await supabase.rpc(
 'add_payment',
  {
    user_id: userId,
    event_url: url,
  }
)
g
When you created your function did you define user_id as type uuid? I also like to name my vars/input parameters different names than the column names just for clarity.
o
yes
g
In your booking insert did you mean column user_id to insert event_url into?
o
no each of those have a column
g
you are saying to insert a row into public.booking with the column user_id set to a string event_url(I assume it is a string)
o
yes
g
is user_id there are string?
o
no its a uuid
g
you can't insert event_url (if it is a string) into that column.
o
event-url is a string and user-id is a uuid
g
I don't think you understand the insert into syntax then.
the stuff in () is column names
o
no sorry probably not
ok
g
the values then go 1 by 1 into the columns you say
o
yes
g
so you are creating a new row with user_id column set to event_url which you can't do
o
no im not
im creating a new row in the booking table with a user_id i already have and a new event_url
g
but you are not...
o
my function is wrong
g
you probably need something like into (user_id, event_url) values user_id, event_url
o
yes
i think so
ok i see let me try that
sorry the i probably copied that wrong
g
you also see why using same names is confusing..
o
yes
g
OK you changed it in the original post, is that a change you made to the code, or are you just correcting the post and still have the error?
o
correcting the post here
g
If you still have the error you should check your actual user_id sent is correct in the post data.
o
ill have to check my code again and see what i can save from the webhook responses. it'll probably be sometime tomorrow. can i reply here if im having problems or start a new thread?
g
Should start a new thread, I'm out alot for awhile.
o
ok no problem thanks Gary