mariadb-information-functions

Reference MariaDB information functions for session, server, and statement metadata in SQL.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-information-functions-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-information-functions
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/functions/mariadb-information-functions
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-information-functions-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct MariaDB SQL requires knowing the exact semantics of information functions like LAST_INSERT_ID, ROW_COUNT, and CURRENT_USER, whose behavior differs subtly from common assumptions and from MySQL-era expectations. ## Core Features & Use Cases - Complete Function Catalog: Covers 21 built-in information functions with signatures and one-line semantic summaries, including VERSION, CONNECTION_ID, CHARSET, COLLATION, and BINLOG_GTID_POS. - Common Pitfall Corrections: Documents what LLMs often get wrong, such as LAST_INSERT_ID returning the first (not last) auto-increment value of a multi-row INSERT, and ROW_COUNT returning -1 after SELECT statements. - Version Awareness: Defaults to MariaDB 11.8 LTS with since-version annotations, including the 11.7 change where SESSION_USER diverges from USER. - Use Case: When writing a stored procedure that must read the authenticated account rather than the connecting user, consult this reference to correctly choose CURRENT_USER over USER and avoid security-relevant mistakes. ## Quick Start Ask the AI which MariaDB function returns the number of rows affected by the previous UPDATE statement and how CLIENT_FOUND_ROWS changes the result.

Frequently Asked Questions about mariadb-information-functions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get the last inserted auto-increment ID in MariaDB?▼

Use LAST_INSERT_ID() immediately after the INSERT on the same connection. It returns the first automatically generated AUTO_INCREMENT value of the statement, is per-connection so concurrent sessions do not interfere, and stored functions or triggers restore the prior value on exit.

What is the difference between USER() and CURRENT_USER() in MariaDB?▼

USER() returns the user and host the client presented at connection, while CURRENT_USER() returns the account actually used for privilege checks. They differ when roles, proxy users, or SQL SECURITY DEFINER stored routines are involved, making the distinction security-relevant.

Why does ROW_COUNT() return -1 after my SELECT query?▼

ROW_COUNT() returns -1 for any statement that produces a result set, including SELECT, SHOW, DESC, and HELP, even when the result is empty. A return of 0 means a DDL or no-result statement genuinely affected nothing.

Should I use SQL_CALC_FOUND_ROWS with FOUND_ROWS() for pagination?▼

No, this is a legacy pattern discouraged for new code because it disables some query optimizations. Prefer a separate SELECT COUNT(*) query with the same WHERE clause to get the total row count alongside a LIMITed page of results.

Does SESSION_USER() behave the same as USER() in all MariaDB versions?▼

No. Before MariaDB 11.7, SESSION_USER() was an alias for USER(). From 11.7 onward it captures CURRENT_USER() at session start and stays fixed inside stored routines and views, while SYSTEM_USER() remains a plain synonym for USER().