Check for value with current_setting()
Please find the below example which i use while working with current_setting.
CREATE OR REPLACE FUNCTION public.usp_fetch_current_setting()
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
v_appCode text;
begin
select current_setting('spm.appCode', 't') into v_appCode;
return v_appCode;
END;
$function$
;
while calling:
set session "spm.appCode" = 'spm-alignment-web';
SELECT public.usp_fetch_current_setting();
9.6 and newer:
PostgreSQL (9.6+) supports current_setting('setting_name', 't')
to fetch a setting and return NULL
if it's unset. you can combine this with coalesce
to supply a default.
9.5 and older:
Per the question, you can do it with a plpgsql
function that uses a BEGIN ... EXCEPTION
handler, if you don't mind the performance hit and clumsiness. But there's no built-in support.