PostgreSQL plsql method with json argument

To get a element of json we can call with index name like this i_json::json->>’bar’
Here is a sample method with josn argument

CREATE OR REPLACE FUNCTION my_sp_method(i_json       JSON) RETURNS TEXT AS $$
BEGIN
 RETURN i_json::json->>'bar';	
END;
$$ LANGUAGE plpgsql;

Calling with a json will return “world” which is the value of json index bar

SELECT my_sp_method('{"foo":"hello", "bar":"world"}'); 

Posted

in

by

Tags: