Reputation: 1001
I am getting a problem while running my function in postgres version 9.3.9 It given me a below error when i run this:
Caused by: org.postgresql.util.PSQLException: ERROR: function json_typeof(json) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Where: PL/pgSQL function myArray(character varying,json) line 9 at SQL statement
Here is my function:
CREATE OR REPLACE FUNCTION myArray(domain_name varchar, val json) RETURNS varchar LANGUAGE plpgsql STABLE AS $$
DECLARE
result varchar;
isarray BOOLEAN;
q cursor for
select json_agg(blogIn(null,b.value))
from json_array_elements_text(val) b;
BEGIN
SELECT json_typeof(val) = 'array' into isarray;
if not isarray THEN
return val;
end if;
open q;
fetch q into result;
close q;
if result is null then
return val;
end if;
return result;
END;
$$;
It is very strange that this function run without any problem in Postgres 9.5 version but on 9.3 it creating above error. Can someone tell me what actually type cast it require at "SELECT json_typeof(val) = 'array' into isarray;" ?
Upvotes: 0
Views: 4467
Reputation: 121604
Surely you'll upgrade your Postgres soon. Before this happens you can use this function:
create or replace function is_json_array(json)
returns boolean language sql immutable as $$
select coalesce(left(regexp_replace($1::text, '\s', '', 'g'), 1) = '[', false)
$$;
Upvotes: 1