简体   繁体   中英

MySQL JSON_TABLE Multiple Nested Paths

I have the following query:

SELECT * FROM
    JSON_TABLE(
    '{"TrackingIds":[-1,-2],"Matrices":[22,23]}' 
    ,"$" COLUMNS(
        NESTED path "$.Matrices[*]" COLUMNS (Matrices INT path '$'),
        NESTED path "$.TrackingIds[*]" COLUMNS (TrackingId INT path '$')
    )) AS  j;

Which yields:

Matrices    TrackingId
22             \N
23             \N
\N             -1
\N             -2

How would I get it produce the below:

Matrices    TrackingId
22             -1
23             -2

Almost like it is a Key Value lookup. Thanks, -Tanner

This is by design. From the MySQL 8 manual :

Sibling nested paths—that is, two or more instances of NESTED [PATH] in the same COLUMNS clause—are processed one after another, one at a time. While one nested path is producing records, columns of any sibling nested path expressions are set to NULL. This means that the total number of records for a single match within a single containing COLUMNS clause is the sum and not the product of all records produced by NESTED [PATH] modifiers.

You need an outer query to group related rows together, or not use NESTED PATH s

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM