I have following function
CREATE OR REPLACE FUNCTION public."test"(
_data text)
RETURNS integer
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$
declare _sdate date:= null;
begin
select json_extract_path(_data:: json , 'sdate') into _sdate;
select _data:: json -> 'sdate' into _sdate;
END;
$BODY$;
I tried both way but it throws syntax error when sdate is null
I am calling like
select public."test"($${
"sdate":null
}$$)
but when I give sdate value it is working
select public."test"($${
"sdate":"2020-1-01"
}$$)
I also tried explicity parsing like
select _data:: json -> 'sdate'::date into _sdate;
But not working