Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Verify dynamic column integrity. This function checks if a blob containing dynamic columns is valid and returns 1 if it is, 0 otherwise.
COLUMN_CHECK(dyncol_blob);Check if dyncol_blob is a valid packed dynamic columns blob. Return value of 1 means the blob is valid, return value of 0 means it is not.
Rationale: Normally, one works with valid dynamic column blobs. Functions like , , always return valid dynamic column blobs. However, if a dynamic column blob is accidentally truncated, or transcoded from one character set to another, it will be corrupted. This function can be used to check if a value in a blob field is a valid dynamic column blob.
This page is licensed: CC BY-SA / Gnu FDL
Manage schema-less data within relational tables. These functions, such as COLUMN_CREATE and COLUMN_GET, allow you to store and retrieve variable sets of columns in a single BLOB field.
Update dynamic columns. This function adds or updates values within a dynamic column blob, returning the new blob content.
COLUMN_ADD(dyncol_blob, column_nr, value [as type], [column_nr, value [as type]]...)
COLUMN_ADD(dyncol_blob, column_name, value [as type], [column_name, value [as type]]...)Adds or updates dynamic columns.
dyncol_blob must be either a valid dynamic columns blob (for example, COLUMN_CREATE returns such blob), or an empty string.
column_name specifies the name of the column to be added. If dyncol_blob already has a column with this name, it will be overwritten.
value specifies the new value for the column. Passing a NULL value will cause the column to be deleted.
as type is optional. See section for a discussion about types.
The return value is a dynamic column blob after the modifications.
Note: COLUMN_ADD() is a regular function (just like ), hence, in order to update the value in the table you have to use the UPDATE ... SET dynamic_col=COLUMN_ADD(dynamic_col, ....) pattern.
This page is licensed: CC BY-SA / Gnu FDL
COLUMN_DELETE(dyncol_blob, column_nr, column_nr...)
COLUMN_DELETE(dyncol_blob, column_name, column_name...)UPDATE t1 SET dyncol_blob=COLUMN_ADD(dyncol_blob, "column_name", "value") WHERE id=1;Create a dynamic column blob. This function generates a binary string containing specified column names and values for storage in a BLOB.
COLUMN_CREATE(column_nr, value [as type], [column_nr, value [as type]]...)
COLUMN_CREATE(column_name, value [as type], [column_name, value [as type]]...)Returns a dynamic columns blob that stores the specified columns with values.
The return value is suitable for
storing in a table;
further modification with other dynamic columns functions.
The as type part allows one to specify the value type. In most cases, this is redundant because MariaDB will be able to deduce the type of the value. Explicit type specification may be needed when the type of the value is not apparent. For example, a literal '2012-12-01' has a CHAR type by default, one will need to specify '2012-12-01' AS DATE to have it stored as a date. See for further details.
This page is licensed: CC BY-SA / Gnu FDL
List dynamic column names. This function returns a comma-separated list of all column names contained within a dynamic column blob.
Limitation: COLUMN_JSON decodes nested dynamic columns at a nesting level of not more than 10 levels deep. Dynamic columns that are nested deeper than 10 levels are shown as BINARY string, without encoding.
This page is licensed: CC BY-SA / Gnu FDL
COLUMN_JSON(dyncol_blob)INSERT INTO tbl SET dyncol_blob=COLUMN_CREATE("column_name", "value");Retrieve a dynamic column value. This function extracts a specific column's value from a dynamic column blob, casting it to a specified type.
COLUMN_GET(dyncol_blob, column_nr as type)
COLUMN_GET(dyncol_blob, column_name as type)Gets the value of a dynamic column by its name. If no column with the given name exists, NULL will be returned.
column_name as type requires that one specify the datatype of the dynamic column they are reading.
This may seem counter-intuitive: why would one need to specify which datatype they're retrieving? Can't the dynamic columns system figure the datatype from the data being stored?
The answer is: SQL is a statically-typed language. The SQL interpreter needs to know the datatypes of all expressions before the query is run (for example, when one is using prepared statements and runs "select COLUMN_GET(...)", the prepared statement API requires the server to inform the client about the datatype of the column being read before the query is executed and the server can see what datatype the column actually has).
Suppose running a query like this:
Without specifying a maximum length (i.e. using as CHAR, not as CHAR(n)), MariaDB will report the maximum length of the result set column to be 16,777,216. This may cause excessive memory usage in some client libraries, because they try to pre-allocate a buffer of maximum result set width. To avoid this problem, use CHAR(n) whenever you're using COLUMN_GET in the select list.
See for more information about datatypes.
This page is licensed: CC BY-SA / Gnu FDL
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"} |
+-----------------+----------------------------------------+SELECT COLUMN_GET(BLOB, 'colname' AS CHAR) ...Check for a dynamic column. This function returns 1 if a specified column exists within a dynamic column blob, and 0 otherwise.