MariaDB10.0.X中,动态列支持JSON格式来获取数据。-创新互联
MariaDB 10.0.X中,动态列(Dynamic Columns),可以支持 JSON 格式来获取数据。
创新互联建站是一家网站设计公司,集创意、互联网应用、软件技术为一体的创意网站建设服务商,主营产品:响应式网站开发、品牌网站建设、网络营销推广。我们专注企业品牌在网站中的整体树立,网络互动的体验,以及在手机等移动端的优质呈现。做网站、成都网站制作、移动互联产品、网络运营、VI设计、云产品.运维为核心业务。为用户提供一站式解决方案,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏析悦目的作品,网站的价值服务。为了兼容传统SQL语法,MariaDB 10和MySQL5.7支持原生JSON格式,即关系型数据库和文档型NoSQL数据库集于一身。
使用说明:
###表结构
###插入JSON格式数据
mysql> INSERT INTO assets VALUES -> ('MariaDB T-shirt', COLUMN_CREATE('color', 'blue', 'size', 'XL')); Query OK, 1 row affected (0.02 sec) mysql> INSERT INTO assets VALUES -> ('Thinkpad Laptop', COLUMN_CREATE('color', 'black', 'price', 500)); Query OK, 1 row affected (0.01 sec)###获取Key(键)color的Value(值):
mysql> SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color FROM assets; +-----------------+-------+ | item_name | color | +-----------------+-------+ | MariaDB T-shirt | blue | | Thinkpad Laptop | black | +-----------------+-------+ 2 rows in set (0.00 sec)###获取全部Key(键)
mysql> SELECT item_name, column_list(dynamic_cols) FROM assets; +-----------------+---------------------------+ | item_name | column_list(dynamic_cols) | +-----------------+---------------------------+ | MariaDB T-shirt | `size`,`color` | | Thinkpad Laptop | `color`,`price` | +-----------------+---------------------------+ 2 rows in set (0.00 sec)###获取全部Key-Value
mysql> SELECT item_name, COLUMN_JSON(dynamic_cols) FROM assets; +-----------------+-------------------------------+ | item_name | COLUMN_JSON(dynamic_cols) | +-----------------+-------------------------------+ | MariaDB T-shirt | {"size":"XL","color":"blue"} | | Thinkpad Laptop | {"color":"black","price":500} | +-----------------+-------------------------------+ 2 rows in set (0.01 sec)###删除一个Key-Value:
mysql> UPDATE assets SET dynamic_cols=COLUMN_DELETE(dynamic_cols, "price") -> WHERE COLUMN_GET(dynamic_cols, 'color' as char)='black'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT item_name, COLUMN_JSON(dynamic_cols) FROM assets; +-----------------+------------------------------+ | item_name | COLUMN_JSON(dynamic_cols) | +-----------------+------------------------------+ | MariaDB T-shirt | {"size":"XL","color":"blue"} | | Thinkpad Laptop | {"color":"black"} | +-----------------+------------------------------+ 2 rows in set (0.00 sec)###增加一个Key-Value:
mysql> UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '3 years') -> WHERE item_name='Thinkpad Laptop'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT item_name, COLUMN_JSON(dynamic_cols) FROM assets; +-----------------+----------------------------------------+ | item_name | COLUMN_JSON(dynamic_cols) | +-----------------+----------------------------------------+ | MariaDB T-shirt | {"size":"XL","color":"blue"} | | Thinkpad Laptop | {"color":"black","warranty":"3 years"} | +-----------------+----------------------------------------+ 2 rows in set (0.00 sec)###更改一个Key-Value:
mysql> UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols,'color', 'white') WHERE COLUMN_GET(dynamic_cols, 'color' as char)='black'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT item_name, COLUMN_JSON(dynamic_cols) FROM assets; +-----------------+----------------------------------------+ | item_name | COLUMN_JSON(dynamic_cols) | +-----------------+----------------------------------------+ | MariaDB T-shirt | {"size":"XL","color":"blue"} | | Thinkpad Laptop | {"color":"white","warranty":"3 years"} | +-----------------+----------------------------------------+ 2 rows in set (0.00 sec)另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享名称:MariaDB10.0.X中,动态列支持JSON格式来获取数据。-创新互联
标题链接:http://azwzsj.com/article/dpdpgs.html