truncate table user_status;
create table user_status(col1 bigint GENERATED BY DEFAULT AS IDENTITY , status text);
create or replace function upd_status(text)
returns bigint language plpgsql
as $$
declare var1 bigint;
begin
with alias1 as (insert into user_status(status) values($1) returning col1)
select * into var1 from alias1;
return var1;
end;$$;
create or replace function lookup_status(text)
returns boolean language plpgsql
immutable parallel safe
as $$
begin return (select exists (select 1 from user_status where status = $1)); end;$$;
create or replace function check_status(text)
returns void language plpgsql
as $$
declare var1 bigint;
begin
var1 := upd_status($1);
if lookup_status($1) then
raise notice 'Status exists as part of immutable check - %', $1;
else
raise notice 'Status does not exists - %', $1;
end if;
raise notice 'Actual Result for status % is %', $1,(select exists (select 1 from user_status where status = $1 and col1 = var1));
end;$$;
create or replace function lookup_status(text)
returns boolean language plpgsql
stable parallel safe
as $$
begin return (select exists (select 1 from user_status where status = $1)); end;$$;