0

I'm currently inserting this data {"curr": "testcurr","nm": "testnm"} to a view.

A trigger function is then run to insert into the original tables instead.

I'm getting an error column "curr" does not exist from the trigger function.

Here is the part of my code:

IF (tg_op = 'INSERT') THEN
                NEW."dat"= jsonb_build_object("curr",NEW."curr","symb",NEW."symb");
                NEW."ct"=now();
                INSERT INTO data.tbl
                    (
                    "nm",
                    "dat",
                    "ct",
                    )
                    VALUES
                    (
                    NEW."nm",
                    NEW."dat"
                    NEW."ct"
                    )returning "id" into NEW.id;
END

As you can see, the original table does not contain the 'curr' column, but my post data shouldn't have any problem right?

1 Answer 1

1

change:

jsonb_build_object("curr",NEW."curr","symb",NEW."symb")

to:

jsonb_build_object('curr',NEW."curr",'symb',NEW."symb")

https://www.postgresql.org/docs/current/static/functions-json.html look at the example - to get key "foo" you pass string 'foo'

double quotes are for identifiers - column, relation etc names - check https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

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

2 Comments

thanks, I got another error now: cannot insert into column "curr" of view "tblview"
apparently you are trying to insert a row into a view, which can't be done by the view origin. that would be the different question and will require different code sample

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.