SQL failed to run. Not sure how to fix.

Hey guys. I'm new to SQL. I would like to implement a new function.

I hope you got my idea from code:
create or replace function fetch_users(user_id text)
returns json as
$func$
  declare @cached_array array
  declare @result json

  select @cached_array = cached 
  from public.kisis_cache 
  where tg_id = $1;

  select @result = *
  from public.kisis_cache 
  where tg_id not in cached_array and status = 'active';

  return @result
$func$
language sql;


In a few words: I would like to initially fetch the array from table. Then return the records from another table where a column is NOT IN that array.
image.png
Was this page helpful?