Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.0Mb
PDF (A4) - 41.0Mb
PDF (RPM) - 39.4Mb
HTML Download (TGZ) - 9.3Mb
HTML Download (Zip) - 9.3Mb
HTML Download (RPM) - 7.9Mb
Man Pages (TGZ) - 260.6Kb
Man Pages (Zip) - 371.7Kb
Info (Gzip) - 3.9Mb
Info (Zip) - 3.9Mb
Excerpts from this Manual

MySQL 8.0 Reference Manual  /  ...  /  Query Attribute User-Defined Functions

5.7.3 Query Attribute User-Defined Functions

  • mysql_query_attribute_string(name)

    Applications can define attributes that apply to the next query sent to the server. The mysql_query_attribute_string() function, available as of MySQL 8.0.23, returns an attribute value as a string, given the attribute name. This function enables a query to access and incorporate values of the attributes that apply to it.

    mysql_query_attribute_string() is installed by installing the query_attributes component. See Section 9.6, “Query Attributes”, which also discusses the purpose and use of query attributes.


    • name: The attribute name.

    Return value:

    Returns the attribute value as a string for success, or NULL if the attribute does not exist.


    The following example uses the mysql client query_attributes command to define query attributes that can be retrieved by mysql_query_attribute_string(). The SELECT shows that retrieving a nonexistent attribute (n3) returns NULL.

    mysql> query_attributes n1 v1 n2 v2;
    mysql> SELECT
        ->   mysql_query_attribute_string('n1') AS 'attr 1',
        ->   mysql_query_attribute_string('n2') AS 'attr 2',
        ->   mysql_query_attribute_string('n3') AS 'attr 3';
    | attr 1 | attr 2 | attr 3 |
    | v1     | v2     | NULL   |

    For additional examples, see Section 9.6, “Query Attributes”.