JSON Data Type
You are viewing an old version of this article. View
the current version here.
MariaDB starting with 10.2.7
The JSON alias was added in MariaDB 10.2.7.
JSON is an alias for LONGTEXT introduced for compatibility reasons with MySQL's JSON data type. MariaDB implements this as a LONGTEXT rather, as the JSON data type contradicts the SQL standard, and MariaDB's benchmarks indicate that performance is at least equivalent.
In order to ensure that a a valid json document is inserted, the JSON_VALID function can be used as a CHECK constraint.
Examples
CREATE TABLE t (j JSON); DESC t; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | j | longtext | YES | | NULL | | +-------+----------+------+-----+---------+-------+
With validation:
CREATE TABLE t2 ( j JSON CHECK (JSON_VALID(j)) );
See also
Comments
Comments loading...
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.