Using this table:
CREATE TABLE t (i int PRIMARY KEY, j variant);
I’m trying to insert some JSON object into the table, e.g.
INSERT INTO t (i, j) VALUES (1, object_construct('a', 1));
However, that fails with:
SQL Error [2014] [22000]: SQL compilation error:
Invalid expression [OBJECT_CONSTRUCT(‘a’, 1)] in VALUES clause
I can work around the problem with this:
INSERT INTO t (i, j) VALUES (1, null);
UPDATE t SET j = object_construct('a', 1) WHERE i = 1;
Why can’t I use OBJECT_CONSTRUCT
in an INSERT
statement?
2
Answers
The manual suggests using
INSERT .. SELECT
:I.e. this works:
However, it does not offer any explanation with respect to the limitation, or why this particular workaround is needed.
INSERT INTO … VALUES:
VALUES:
Same applies to both
OBJECT_CONSTRUCT
and OBJECT curly braces :