I have the following schema:
CREATE TABLE survey_results (
id integer NOT NULL,
publish_id integer,
raw jsonb DEFAULT '{}'::jsonb
);
INSERT INTO survey_results (id, raw)
VALUES (1, '{"survey": {"publish_id": 5}}');
I want to copy value from jsonb field to integer column with the following update:
UPDATE survey_results SET publish_id = raw#>>'{survey, publish_id}';
But this returns me:
ERROR: column "publish_id" is of type integer but expression is of type text Hint: You will need to rewrite or cast the expression. Position: 40
How can I fix that?