0

I tried to create generated column from other JSON type column with ALTER TABLE "Invoice" ADD COLUMN created Integer GENERATED ALWAYS AS (data ->> 'created') STORED;

When I execute this I get error ERROR: column "created" is of type integer but default expression is of type text HINT: You will need to rewrite or cast the expression. SQL state: 42804

I tried to cast it with CAST function and :: operator but with no lack. Is there any way to do it? Or maybe I should generate this column differently?

Thanks

1 Answer 1

1

How about converting the value to an int?

ALTER TABLE "Invoice" ADD COLUMN created Integer
    GENERATED ALWAYS AS ( (data ->> 'created')::int ) STORED;
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.