MySQL Tutorials - Herong's Tutorial Examples - v4.46, by Herong Yang
Table Column Types for JSON Documents
Describes 1 type of table column to store JSON documents: JSON.
There is 1 type of table column to store JSON documents: JSON.
"JSON" - A JSON document.
Examples of look up value column types, JsonColumns.sql:
-- JsonColumns.sql -- Copyright (c) 2005 HerongYang.com. All Rights Reserved. -- CREATE TABLE JsonDoc ( Line VARCHAR(2), J JSON, T TEXT ); INSERT INTO JsonDoc VALUES ( '1', '[99, {"id": "HK500", "cost": 75.99}, ["hot", "cold"]]', '[99, {"id": "HK500", "cost": 75.99}, ["hot", "cold"]]' ); SELECT * FROM JsonDoc; SELECT Line, JSON_TYPE(J), JSON_TYPE(T) FROM JsonDoc; SELECT Line, CHAR_LENGTH(J), CHAR_LENGTH(T) FROM JsonDoc; DROP TABLE JsonDoc;
Running JsonColumns.sql on MySQL 8.0 server gives you:
herong> %mysql%\bin\mysql --user=root --password=TopSecret test \ < JsonColumns.sql Line J T 1 [99, {"id": "HK500", "cost": 75.99}, ["hot", "cold"]] [99, {"id": "HK500", "cost": 75.99}, ["hot", "cold"]] Line JSON_TYPE(J) JSON_TYPE(T) 1 ARRAY ARRAY Line CHAR_LENGTH(J) CHAR_LENGTH(T) 1 53 53
Note that there are not many differences between JSON and TEXT columns.
Table of Contents
MySQL Introduction and Installation
Introduction of MySQL Programs
Perl Programs and MySQL Servers
Java Programs and MySQL Servers
Character Strings and Bit Strings
►Table Column Types for Different Types of Values
Table Column Types for Character Strings
Table Column Types for Byte Strings
Table Column Types for Bit Strings
Table Column Types for Exact Numbers
Table Column Types for Approximate Numbers
Table Column Types for Date and Time Values
Table Column Types for LOB (Large OBject)
Table Column Types for Look Up Values
►Table Column Types for JSON Documents
Table Column Types for Spatial Geometry Data
Using DDL to Create Tables and Indexes
Using DML to Insert, Update and Delete Records
Using SELECT to Query Database
Window Functions for Statistical Analysis
Use Index for Better Performance
Transaction Management and Isolation Levels
Defining and Calling Stored Procedures
Variables, Loops and Cursors Used in Stored Procedures
System, User-Defined and Stored Procedure Variables
Storage Engines in MySQL Server
InnoDB Storage Engine - Primary and Secondary Indexes
Performance Tuning and Optimization
Installing MySQL Server on Linux