https://supabase.com/ logo
#help
Title
# help
a

akshg05

01/29/2022, 4:27 PM
My use case is pretty simple. I need to increment a column from a group of users whose IDs I pass as an array.
g

garyaustin

01/29/2022, 4:33 PM
You pretty much can search the internet for postgresql functions and describe what you want and probably get close. I have a simple function using an array input:
Copy code
create function get_by_ids(ids bigint[]) returns SETOF messages
    language plpgsql
as
$$
begin
    return query
      select * from messages where id in (ids);
    end;
$$;
You could pass in json and get the ids from that, just have to ask in sql thread or google plpgsql array from json or some such. I don't know the syntax without searching for it.
a

akshg05

01/29/2022, 4:48 PM
Thank you. I was thinking of that approach. I'm looking for it.
I couldn't find a proper way to extract array from json yet :/ I'm very new to the SQL and postgresql world.
g

garyaustin

01/29/2022, 5:58 PM
SELECT json_array_elements('[1,true, [2,false]]'); https://www.w3resource.com/PostgreSQL/postgresql-json-functions-and-operators.php hopefully that gets you going