Information functions
VERSION, DATABASE, USER, CURRENT_USER, CONNECTION_ID, LAST_INSERT_ID, ROW_COUNT, FOUND_ROWS, CHARSET and COLLATION.
These functions report on the session and the server. They are not deterministic, so they cannot be used in a generated column, a functional index or a CHECK constraint (the server refuses them as MySQL does).
COERCIBILITY(x) is worked out from what is written (explicit COLLATE 0, column 2, system constant 3, literal 4, number 5, NULL 6). CHARSET and COLLATION read COLLATE and N'..'. Not supported yet: BENCHMARK, CURRENT_ROLE, FORMAT_BYTES.
Summary of functions#
| Function | What it does | Dialect |
|---|---|---|
CHARSET | Returns the character set of the argument: utf8mb4 for text, binary for anything else. | MySQL and MariaDB |
COLLATION | Returns the collation of the argument: the connection's collation for text (utf8mb4_0900_ai_ci in the MySQL dialect, utf8mb4_general_ci in the MariaDB dialect), binary for anything else. | MySQL and MariaDB |
CONNECTION_ID | Returns the number of the connection (the thread id the server gave it). | MySQL and MariaDB |
CURRENT_USER | Returns the account (user@host) whose privileges the session has, as it is named in the account table. | MySQL and MariaDB |
DATABASE | Returns the name of the default database, NULL if there is none. | MySQL and MariaDB |
FOUND_ROWS | Returns the number of rows the last SELECT found; after `SELECT SQL_CALC_FOUND_ROWS ... | MySQL and MariaDB |
LAST_INSERT_ID | Returns the first AUTO_INCREMENT value the last INSERT of this session generated (not the last of a multi-row INSERT). | MySQL and MariaDB |
ROW_COUNT | Returns the number of rows the last statement changed (inserted, updated, deleted), -1 for a statement that returns rows. | MySQL and MariaDB |
SESSION_USER | Return the user name and host the client connected as (user@host). | MySQL and MariaDB |
VERSION | Returns the server version: 8.0.36-Raft DB as MySQL, 11.4.13-MariaDB-Raft DB as MariaDB. | MySQL and MariaDB |
CHARSET#
CHARSET(str)Returns the character set of the argument: utf8mb4 for text, binary for anything else. Every text of Raft DB is utf8mb4.
Example:
SELECT CHARSET('a'), CHARSET(1);Result: utf8mb4, binary
COLLATION#
COLLATION(str)Returns the collation of the argument: the connection's collation for text (utf8mb4_0900_ai_ci in the MySQL dialect, utf8mb4_general_ci in the MariaDB dialect), binary for anything else.
Example:
SELECT COLLATION('a'), COLLATION(1);Result: utf8mb4_0900_ai_ci (MySQL dialect), binary
CONNECTION_ID#
CONNECTION_ID()Returns the number of the connection (the thread id the server gave it).
Example:
SELECT CONNECTION_ID();Result: a number, the id shown by SHOW PROCESSLIST
CURRENT_USER#
CURRENT_USER()
CURRENT_USERReturns the account (user@host) whose privileges the session has, as it is named in the account table.
Example:
SELECT CURRENT_USER();Result: for example root@%
DATABASE#
DATABASE()
SCHEMA()Returns the name of the default database, NULL if there is none. SCHEMA is a synonym.
Example:
SELECT DATABASE();Result: the name given by USE, or NULL
FOUND_ROWS#
FOUND_ROWS()Returns the number of rows the last SELECT found; after SELECT SQL_CALC_FOUND_ROWS ... LIMIT n the number it would have found without the LIMIT.
Example:
SELECT SQL_CALC_FOUND_ROWS id FROM t LIMIT 2;
SELECT FOUND_ROWS();Result: the number of rows of t
LAST_INSERT_ID#
LAST_INSERT_ID()Returns the first AUTO_INCREMENT value the last INSERT of this session generated (not the last of a multi-row INSERT). It is kept per session, so another session's inserts do not change it. The form LAST_INSERT_ID(expr) is not supported: the argument is ignored.
Example:
INSERT INTO seq (v) VALUES ('x'), ('y'), ('z');
SELECT LAST_INSERT_ID(), MAX(id) FROM seq;Result: the id of the row x, then the id of z
ROW_COUNT#
ROW_COUNT()Returns the number of rows the last statement changed (inserted, updated, deleted), -1 for a statement that returns rows. An UPDATE that sets a column to the value it has does not count the row.
Example:
UPDATE words SET n = n;
SELECT ROW_COUNT();Result: 0
SESSION_USER#
SESSION_USER()
SYSTEM_USER()
USER()Return the user name and host the client connected as (user@host). They are synonyms.
Example:
SELECT USER();Result: for example root@localhost
VERSION#
VERSION()Returns the server version: 8.0.36-Raft DB as MySQL, 11.4.13-MariaDB-Raft DB as MariaDB.
Example:
SELECT VERSION();Result: 8.0.36-Raft DB in the MySQL dialect