MariaDB 10.0.X中,動(dòng)態(tài)列(Dynamic Columns),可以支持 JSON 格式來(lái)獲取數(shù)據(jù)。
創(chuàng)新互聯(lián)建站是一家網(wǎng)站設(shè)計(jì)公司,集創(chuàng)意、互聯(lián)網(wǎng)應(yīng)用、軟件技術(shù)為一體的創(chuàng)意網(wǎng)站建設(shè)服務(wù)商,主營(yíng)產(chǎn)品:響應(yīng)式網(wǎng)站開(kāi)發(fā)、品牌網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣。我們專(zhuān)注企業(yè)品牌在網(wǎng)站中的整體樹(shù)立,網(wǎng)絡(luò)互動(dòng)的體驗(yàn),以及在手機(jī)等移動(dòng)端的優(yōu)質(zhì)呈現(xiàn)。做網(wǎng)站、成都網(wǎng)站制作、移動(dòng)互聯(lián)產(chǎn)品、網(wǎng)絡(luò)運(yùn)營(yíng)、VI設(shè)計(jì)、云產(chǎn)品.運(yùn)維為核心業(yè)務(wù)。為用戶(hù)提供一站式解決方案,我們深知市場(chǎng)的競(jìng)爭(zhēng)激烈,認(rèn)真對(duì)待每位客戶(hù),為客戶(hù)提供賞析悅目的作品,網(wǎng)站的價(jià)值服務(wù)。為了兼容傳統(tǒng)SQL語(yǔ)法,MariaDB 10和MySQL5.7支持原生JSON格式,即關(guān)系型數(shù)據(jù)庫(kù)和文檔型NoSQL數(shù)據(jù)庫(kù)集于一身。
使用說(shuō)明:
###表結(jié)構(gòu)
###插入JSON格式數(shù)據(jù)
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)###刪除一個(gè)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)###增加一個(gè)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)###更改一個(gè)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)另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。