There seems to be an interesting combination of features that lead to an error in Db2 LUW v11.5.0.0. To reproduce, write:
CREATE TABLE t (a INT);
INSERT INTO t VALUES (1), (2);
SELECT '[' || listagg(
json_object(
KEY 'a' VALUE a,
KEY 'b' VALUE b
), ','
) WITHIN GROUP (ORDER BY a) || ']'
FROM (
SELECT a, NULL b
FROM t
ORDER BY a
);
I'm using LISTAGG
to work around Db2 LUW's missing JSON_ARRAYAGG
support.
The error I'm getting is this:
The SQL statement or command failed because of a database system error. (Reason "invalid qnc assigment".). SQLCODE=-901, SQLSTATE=58004, DRIVER=4.7.85
Quite probably a bug in the parser. There doesn't seem to be anything obviously wrong. How can this be prevented / worked around?
NULL
values in Db2. Despite the fact thatCALL ADMIN_CMD('DESCRIBE SELECT 1 a, NULL b FROM sysibm.sysdummy1')
returnsVARCHAR(1)
forb
, it's only implicit guessing. Db2 should know exact column data type to use the value properly further... – Mark BarinsteinNULL
values much better. But the workarounds I've documented show that this is just a plain simple bug. There's no valid reason for this error. For example, removing theORDER BY
clause in the derived table "fixes it", or theCOALESCE(b, NULLIF(1, 1))
hack, too. – Lukas EderJSON
null for MySQL:select j, j is null, j = 'null', j = CAST('null' AS JSON) FROM (SELECT json_extract('{"x":null}' ,'$.x') AS j) t
demo – Lukasz Szozda