ak4zh
03/26/2022, 7:57 AMsql
CREATE FUNCTION node_cte(node_ids int[], org_id uuid)
...
WHERE table.id IN node_ids
How can I use the function arg to find all rows whose id is in the arg array.
The above gives array at or near INScott P
03/26/2022, 4:37 PM&&
might be the answer.
Example: I have rows which have an array of days - e.g. any combination of 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'
, and they're stored in the days_available
column . If I wanted to find all rows which include 'MON'
or `'FRI`', then I'd do this:
sql
SELECT * FROM my_table
WHERE
ARRAY(['MON', 'FRI']) && days_available
That'd return any rows which include 'MON'
or 'FRI'
in the days_available
columngaryaustin
03/26/2022, 5:02 PMcreate function get_by_ids(ids bigint[]) returns SETOF messages
language plpgsql
as
$$
begin
return query
select * from messages where id in (ids);
end;
$$;
ak4zh
03/27/2022, 8:05 AMselect * from messages where id in (1,2,3);
but when called from frontend it probably come as
sql
-- the variable node_ids comes as [1,2,3]
-- so it becomes
select * from messages where id in ([1,2,3]);
ak4zh
03/27/2022, 8:19 AMjs
{"message":"operator does not exist: bigint = bigint[]","code":"42883","details":null,"hint":"No operator matches the given name and argument types. You might need to add explicit type casts."}
ak4zh
03/27/2022, 10:27 AMselect * from messages where id = ANY(ids);
this works