2

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.

4
  • 2
    Old postgresql did not support jsonb. There is nothing you can do except for upgrading your postgresql server Commented Feb 12, 2021 at 7:09
  • @mvp Any way I can modify my Query? Commented Feb 12, 2021 at 7:16
  • Also, Can you tell me in which version after 9.4 did PostgreSQL start supporting jsonb. @mvp Commented Feb 12, 2021 at 7:18
  • 1
    9.4 is no longer supported or maintained anyway. And if you upgrade, you should upgrade to the latest version. So just go for Postgres 13 Commented Feb 12, 2021 at 7:39

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.