Reputation: 127
I have PostgreSQL v12 and this code works fine for me in this version. I have no idea if this is a version issue or not but I want to use POSTGRESQL v9.4
----------------------- Function Start v1.0 ------------------------------
drop function if exists aa_Dev.VDN();
CREATE OR REPLACE FUNCTION aa_dev.VDN()
RETURNS VOID AS
$$
declare
tempp json;
begin
DROP TABLE IF EXISTS aa_dev.sdg_vdn;
CREATE TABLE IF NOT EXISTS aa_dev.sdg_vdn (
VDN INT,
skills INT[]
);
tempp := (select VDN_group from aa_dev.sdg_metadata);
insert into aa_dev.sdg_vdn (vdn, skills)
select (jsonb_populate_record(null::aa_dev.sdg_vdn, to_jsonb(t))).*
from jsonb_each(tempp::jsonb) as t(vdn, skills);
end
$$
LANGUAGE plpgsql;
----------------- Function Ends ----------------------
select * from aa_dev.VDN();
select * from aa_dev.sdg_vdn;
So the error is
SQL Error [42883]: ERROR: function to_jsonb(text, jsonb) 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 aa_dev.vdn() line 17 at SQL statement
How can I eliminate this error and run the function in postgresql 9.4. I have a restriction with this version.
Upvotes: 2
Views: 6227
Reputation: 1781
There is some support to jsonb in version 9.4. https://www.postgresql.org/docs/9.4/functions-json.html
You can instead of to_jsonb(t)
use to_json(t)::jsonb
Upvotes: 2