简体   繁体   English

MariaDB动态列嵌套

[英]MariaDB Dynamic Column Nesting

I have been searching for this for a couple of hours. 我已经搜索了两个小时。 I have setup a MariaDB server and am implementing Dynamic Columns, which I know how to do, but I can't seem to find out how to go more than one level deep. 我已经安装了MariaDB服务器并正在实现“动态列”,我知道该怎么做,但是我似乎找不到更多的方法。

INSERT INTO Invoices (Invoice) VALUES (
    COLUMN_CREATE ('Monthly Fee', 500)
);

This works, but what I need is something that will allow me to have something like the following SELECT for JSON: 这可行,但是我需要的是使我能够拥有类似于JSON的以下SELECT的东西:

{
    "services": {
        "Monthly Fee": 500,
        "OnSite": {
            "Units": 10,
            "Rate": 35
        },
        "Mileage": {
            "Units": 181.8,
            "Rate": 0.5
        },
        "Hard Drive Purchase": {
            "Units": 1,
            "Rate": 68.99
        }
    }
}

I just can't figure out how to get the value of the key to be another dynamic column with its own key:value pairs. 我只是不知道如何获得键的值成为另一个具有自己的key:value对的动态列。

I have tried: 我努力了:

INSERT INTO Invoices (Invoice) VALUES (
    COLUMN_CREATE ('Monthly Fee', 500,
        'OnSite',
        COLUMN_CREATE('Units',10,'Rate','35')
    )
);

with nesting where I need it. 在需要的地方嵌套。 I'm hoping this is possible and that I just have a simple syntax error. 我希望这是可能的,而且我只是有一个简单的语法错误。

Any help would be greatly appreciated. 任何帮助将不胜感激。

For anyone that might be trying to figure this out: 对于任何可能试图弄清楚这一点的人:

It was a syntax error. 这是语法错误。 The following syntax gives me what I needed: 以下语法提供了我所需的内容:

SET @tmp = column_create (
    'services',
    column_create (
        'RMM',
        column_create ('Rate', 650),
        'OnSite',
        column_create ('Units', 10, 'Rate', 35),
        'Mileage',
        column_create ('Units', 181.8, 'Rate', 0.50),
        'Hard Drive Purchase',
        column_create ('Units', 1, 'Rate', 68.99)
    )
);

SELECT
    COLUMN_JSON (@tmp);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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