```sql CREATE FUNCTION node_cte(node_ids int[], or...
# sql
a
Copy code
sql
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 IN
s
I'm not sure if this is what you're looking for, but
&&
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:
Copy code
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
column
g
Try WHERE table.id IN (node_ids) with the parenthesis. I use this function currently:
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;
$$;
a
Do you call that function from frontend supbase-js? Because it works when I run from sql
select * from messages where id in (1,2,3);
but when called from frontend it probably come as
Copy code
sql
-- the variable node_ids comes as [1,2,3]
-- so it becomes
select * from messages where id in ([1,2,3]);
Results in following error:
Copy code
js
{"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."}
select * from messages where id = ANY(ids);
this works