get_option

NAME

get_option(): Extract value from options dictionary based on key

TYPE

Function

DESCRIPTION

get_option() accepts a simple dictionary and a key, and extract the value which maps to give nkey within the dictionary.

The dictionary is similar in format to Python's dictionary or to JavaScript's shallow JSON object. For example, consider the following:

{name: "Wallace", num_children: 0, "pet": Gromit}
In the above there are three entries, each with key and value. Either key or value can be quoted, but mostly do not have to be. Quotes are essential when the characters "," or ";" appear within name or value.

Everything is considered to be a string, even if a number is provided. Key and value may consist of any character, and neither are limited to alphanumeric values. They may contain spaces, though these are best used within quotes.

The dictionary cannot have sub-dictionaries. Any such values are treated as text.

There may be multiple entries for the same key, in which case get_option() returns the first one defined. When a key does not exist the function returns NULL. The value NULL, when not quoted, is interpreted as the SQL NULL value.

Upon error (e.g. incorrect dictionary definition) the function returns NULL.

SYNOPSIS

get_option(options TEXT CHARSET utf8, key_name VARCHAR(255) CHARSET utf8) 
  RETURNS TEXT CHARSET utf8

Input:

  • options: a dictionary, in Python-style format (see examples following)
  • key_name: entry to look for within the dictionary.

EXAMPLES

Get an existing value:

mysql> SELECT get_option('{name: "Wallace", num_children: 0, "pet": Gromit}', 'pet') AS result;
+--------+
| result |
+--------+
| Gromit |
+--------+

Attempt to read an unmapped value:

mysql> SELECT get_option('{name: "Wallace", num_children: 0, "pet": Gromit}', 'wife') AS result;
+--------+
| result |
+--------+
| NULL   |
+--------+

ENVIRONMENT

MySQL 5.1 or newer

SEE ALSO

split_token()

AUTHOR

Shlomi Noach
 
common_schema documentation