Is it possible to have a PLPGSQL function take an ...
# sql
d
Is it possible to have a PLPGSQL function take an entire row as a single param to insert it? and would it even be a good idea? e.g. something like this:
Copy code
sql
create or replace function create_planet(new_planet "planet")
returns varchar
language plpgsql
as $$
declare
  new_row bigint;
begin
  insert into public."planets"(new_planet)
  values(new_planet)
  returning "id" into new_row;
  return new_row;
end;
$$
Just to provide some context as to why I want to do this: I have a table where anonymous users can read and write to provided they have access to the correct UUID. However, I don't want the table to be entirely open (since then you can just
SELECT *
all records), so I want to enable RLS and expose the required functionality through RPCs. But I don't really feel like adding every column of the table as a param, since it would become a huge method
All I need to do is to select/create/update (or upsert) a row in this table by uuid
s
You would need to define all columns
You can set the RLS rule to allow read and write based on the UUID
d
hmm that sounds like a better solution
would save me from creating potentially janky rpc calls
Could you perhaps provide an example on how a policy like that would look like? With UUID I mean an id of a row in the table, not
auth.uid()
I haven't been able to find any examples myself
s
You would have to create your own JWT containing the UUID and send along with the request https://github.com/supabase/supabase/discussions/1849
d
thanks, I'll look into it!