MySQL的JSON操作

news2024/9/25 17:14:03

官网地址

1. MySQL json介绍

  • As of MySQL 5.7.8, MySQL supports a native JSON data type defined by RFC 7159 that enables efficient access to data in JSON (JavaScript Object Notation) documents.

  • Automatic validation of JSON documents stored in JSON columns. Invalid documents produce an error.

  • Optimized storage format. JSON documents stored in JSON columns are converted to an internal format that permits quick read access to document elements.

  • It is important to keep in mind that the size of any JSON document stored in a JSON column is limited to the value of the max_allowed_packet system variable.
    在这里插入图片描述

  • A JSON column cannot have a non-NULL default value.

  • In MySQL, JSON values are written as strings. MySQL parses any string used in a context that requires a JSON value, and produces an error if it is not valid as JSON. These contexts include inserting a value into a column that has the JSON data type and passing an argument to a function that expects a JSON value (usually shown as json_doc or json_val in the documentation for MySQL JSON functions)

  • MySQL handles strings used in JSON context using the utf8mb4 character set and utf8mb4_bin collation.

  • Case sensitivity also applies to the JSON null, true, and false literals, which always must be written in lowercase.

  • In MySQL 5.7.9 and later, you can use column->path with a JSON column identifier and JSON path expression as a synonym for JSON_EXTRACT(column, path).

在这里插入图片描述

2. JSON Function Reference

在这里插入图片描述
在这里插入图片描述
MySQL 5.7.22 and later supports two aggregate JSON functions JSON_ARRAYAGG() and JSON_OBJECTAGG().
Also beginning with MySQL 5.7.22:

  • “pretty-printing” of JSON values in an easy-to-read format can be obtained using the JSON_PRETTY() function.
  • You can see how much storage space a given JSON value takes up using JSON_STORAGE_SIZE().

3. Functions That Create JSON Values

mysql> SELECT JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME());
+---------------------------------------------+
| JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME()) |
+---------------------------------------------+
| [1, "abc", null, true, "11:30:24.000000"]   |
+---------------------------------------------+

mysql> SELECT JSON_OBJECT('id', 87, 'name', 'carrot');
+-----------------------------------------+
| JSON_OBJECT('id', 87, 'name', 'carrot') |
+-----------------------------------------+
| {"id": 87, "name": "carrot"}            |
+-----------------------------------------+

mysql> SELECT JSON_QUOTE('null'), JSON_QUOTE('"null"');
+--------------------+----------------------+
| JSON_QUOTE('null') | JSON_QUOTE('"null"') |
+--------------------+----------------------+
| "null"             | "\"null\""           |
+--------------------+----------------------+
mysql> SELECT JSON_QUOTE('[1, 2, 3]');
+-------------------------+
| JSON_QUOTE('[1, 2, 3]') |
+-------------------------+
| "[1, 2, 3]"             |
+-------------------------+








Converting between JSON and non-JSON values

在这里插入图片描述

on duplicate key

mysql> CREATE TABLE `t_json` (
    ->   `id` int NOT NULL AUTO_INCREMENT,
    ->   `json_val` json DEFAULT NULL,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=InnoDB AUTO_INCREMENT=9;
mysql> select * from t_json;
Empty set (0.00 sec)

mysql> insert into t_json values(1, '[123]') on duplicate key update json_val=JSON_ARRAY_APPEND(json_val, '$', 1);
Query OK, 1 row affected (0.00 sec)

mysql> 
mysql> 
mysql> 
mysql> select * from t_json;
+----+----------+
| id | json_val |
+----+----------+
|  1 | [123]    |
+----+----------+
1 row in set (0.00 sec)

mysql> 
mysql> insert into t_json values(1, '[123]') on duplicate key update json_val=JSON_ARRAY_APPEND(json_val, '$', 1);
Query OK, 2 rows affected (0.00 sec)

mysql> select * from t_json;
+----+----------+
| id | json_val |
+----+----------+
|  1 | [123, 1] |
+----+----------+
1 row in set (0.00 sec)

mysql> insert into t_json values(1, '[123]') on duplicate key update json_val=JSON_ARRAY_APPEND(json_val, '$', 1);
Query OK, 2 rows affected (0.00 sec)

mysql> select * from t_json;
+----+-------------+
| id | json_val    |
+----+-------------+
|  1 | [123, 1, 1] |
+----+-------------+
1 row in set (0.01 sec)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/809890.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

CAPL(vTESTStudio) - CANCANFD信号检查

目录 一、获取目标报文数据 二、解析预期信号数据在目标报文中的数据

np.bincount、np.digitize、np.unique、np.histogram、np.searchsorted

np.bincount 简介 np.bincount是统计数组中数字出现数量的函数,数值n在输入数组x中每出现1次,则输出o的o[n]1。 函数 官方文档 函数参数: x: 输入,1维非负数组weights: 权重数组, 可选参数,如果指定了这一参数&am…

HCIP OSPF远离骨干非骨干区域-使用虚链路解决

虚链路 虚链路是OSPF针对不规则区域提出的一种解决方案,也被称为虚连接。 虚链路可以在任意两个ABR上建立,但是要求这两个ABR都有端口连接到一个相同的非骨干区域。 注:虚链路的建立是双向的,虚链路永远属于骨干区域&#xff0…

【学习笔记】关于图像YUV格式分类和排布方式的全学习

这里是尼德兰的喵学习笔记相关文章,欢迎您的访问! 如果文章对您有所帮助,期待您的点赞收藏 让我们一起为芯片前端全栈工程师而努力 目录 前言 YUV格式导图 YUV444 packed planar I444 YV24 semi-planar NV24 NV42 YUV422 packed …

pytorch(6)——神经网络基本骨架nn.module的使用

1 神经网络框架 1.1 Module类的使用 NN (Neural network): 神经网络 Containers: 容器 Convolution Layers: 卷积层 Pooling layers: 池化层 Padding Layers: 填充层 Non-linear Activations (weighted sum, nonlinearity): 非线性激活 Non-linear Activations (other): 非线…

mpi4py包安装报错

报错情况 #include <mpi.h>^~~~~~~compilation terminated.failure.removing: _configtest.c _configtest.oerror: Cannot compile MPI programs. Check your configuration!!![end of output]note: This error originates from a subprocess, and is likely not a probl…

设备取电芯片LDR6328Q

2021年5月&#xff0c;USB-IF 协会发布了全新的USB PD3.1规范&#xff0c;该规范将快充功率上限从100 W提升至240W&#xff08;支持Extended Power Range&#xff0c;简称EPR&#xff09;。充电功率的提升也让USB PD的应用从手机、笔记本电脑&#xff0c;扩展到便携式设备、物联…

Flowable-中间事件-消息中间抛出事件

定义 消息中间事件指在流程中将一个消息事件作为独立的节点来运行。它是一种抛出事件&#xff0c;当流程 执行到消息中间事件时就会中断在这里&#xff0c;一直等待被触发&#xff0c;直接到该事件接收到相应的消息后&#xff0c;流 程沿后继路线继续执行。消息事件是一种引用…

页面访问控制远程仓库

页面访问权限控制 什么是jwt身份认证 在前后端分离模式的开发中&#xff0c;服务器如何知道来访者的身份呢&#xff1f; 在登录后&#xff0c;服务器会响应给用户一个 令牌 &#xff08;token&#xff09;令牌中会包括该用户的id等唯一标识浏览器收到令牌后&#xff0c;自己…

数据结构入门指南:链表(新手避坑指南)

目录 前言 1.链表 1.1链表的概念 1.2链表的分类 1.2.1单向或双向 1.2.2.带头或者不带头 1.2.33. 循环或者非循环 1.3链表的实现 定义链表 总结 前言 前边我们学习了顺序表&#xff0c;顺序表是数据结构中最简单的一种线性数据结构&#xff0c;今天我们来学习链表&#x…

数据结构: 线性表(顺序表实现)

文章目录 1. 线性表的定义2. 线性表的顺序表示:顺序表2.1 概念及结构2.2 接口实现2.2.1 顺序表初始化 (SeqListInit)2.2.2 顺序表尾插 (SeqListPushBack)2.2.3 顺序表打印 (SeqListPrint)2.2.6 顺序表销毁 (SeqListDestroy)2.2.5 顺序表尾删 (SeqListPopBack)2.2.6 顺序表头插 …

vue中各种混淆用法汇总

✨在生成、导出、导入、使用 Vue 组件的时候&#xff0c;像我这种新手就会常常被位于不同文件的 new Vue() 、 export default{} 搞得晕头转向。本文对常见用法汇总区分 new Vue() &#x1f4a6;Vue()就是一个构造函数&#xff0c;new Vue()是创建一个 vue 实例。该实例是一个…

UE5 与 C++ 入门教程·第二课:动画重定向

虚幻中的角色动画都是基于 骨骼网格体 &#xff08;Skeletal Mesh&#xff09;实现&#xff0c;换言之&#xff0c;动画是跟骨骼网格体绑定的。如果有两个骨骼网格体&#xff0c;各自有一套角色动画&#xff0c;那么就可以通过重定向&#xff08;Retargeting&#xff09;将两个…

cglib动态代理、jdk动态代理及spring动态代理使用

1.项目初始化 1.1 pom.xml <dependencies><!-- spring依赖 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.5.RELEASE</version></dependency>&l…

6个电池均衡,buckboost电路,精度高,均衡速度快,BMS均衡

6个电池均衡&#xff0c;buckboost电路&#xff0c;精度高&#xff0c;均衡速度快&#xff0c;本人原创。 1、主体电路图如下 2、均衡电压如图 3、平均电压波动图

SpringBoot使用PropertiesLauncher加载外部jar包

启用SpringBoot的PropertiesLauncher 使用SpringBoot的PropertiesLauncher可以优先加载外部的jar文件, 这样可以在程序运行前替换jar包, 官方文档: Launching Executable Jars 使用演示 建立一个SpringBoot工程, 工程中依赖一个叫自定义的utils包, 版本是1.0.0, 通过http接口…

Java基础_网络编程

Java基础_网络编程 网络编程三要素InetAddress网络模型 UDP通信程序单播发送数据接收数据聊天室 组播广播 TCPTCP通信程序三次握手和四次挥手 来源Gitee地址 网络编程三要素 IP: 设备在网络中的地址&#xff0c;是唯一的标识端口号: 应用程序在设备中唯一的标识。协议: 数据在…

2023OpenFeign源码

原理-源码 让我们看着源~码~ 按顺序走~趟流~程~ 分为两大部分&#xff1a;启动原理、调用流程 Feign 的Java 代码才 3w 多行&#xff0c;放眼现在热门的开源项目&#xff0c; Dubbo、Naocs、Skywalking 中 Java 代码都要 30w 行起步。 重要通知&#xff01;看源码&#xff0c;…

Winform制作的用户界面在高DPI下缩放问题

引言 熟悉Winform的小伙伴应该都遇到过 在100%缩放下制作的用户界面在其他缩放百分比下会出现字体超出边框的情况&#xff0c;导致用户体验大打折扣。用户程序DPI感知是默认打开的&#xff0c;此时可以通过关闭这种感知来禁用字体的缩放&#xff0c;在这种情况下&#xff0c;用…

C语言指针详解

目录 指针是什么? 指针和指针类型 指针-整数 指针的解引用 野指针 野指针成因 如何规避野指针 指针运算 指针- 整数 指针-指针 指针的关系运算 指针和数组 二级指针 指针数组 指针数组 模拟二维数组 指针是什么? 指针理解的2个要点: 1. 指针是内存中一个…