mariadb-numeric-functions

Catalogs MariaDB numeric and math functions with signatures and semantic summaries.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct arithmetic SQL in MariaDB requires knowing subtle behaviors like decimal division, rounding rules, and division-by-zero handling that differ from other databases and languages. ## Core Features & Use Cases - Complete Function Catalog: Covers 36 built-in numeric functions including ROUND, TRUNCATE, FLOOR, CEILING, POW, SQRT, LOG, trigonometry, RAND, CONV, CRC32, and FORMAT with signatures and one-line summaries. - Common Pitfall Corrections: Documents what LLMs often get wrong, such as / always returning a decimal, ROUND using half-away-from-zero for DECIMAL, and RAND being unsuitable for security tokens. - Use Case: When writing a query that calculates financial totals, use this Skill to choose DECIMAL over FLOAT, apply ROUND correctly, and avoid division-by-zero surprises under strict sql_mode. ## Quick Start Ask the AI to write a MariaDB query that rounds monetary values to two decimals and handles integer division correctly using this Skill.

Frequently Asked Questions about mariadb-numeric-functions

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

FAQPage Schema
How do I do integer division in MariaDB?▼

Use the DIV operator for integer division in MariaDB, which discards the remainder and returns a BIGINT-based integer. The / operator always returns a decimal, so 7/2 gives 3.5000 while 7 DIV 2 gives 3.

How does ROUND work in MariaDB for decimal values?▼

ROUND in MariaDB rounds half away from zero for DECIMAL and exact values, so ROUND(2.5) returns 3 and ROUND(-2.5) returns -3. For FLOAT and DOUBLE, the platform C library decides, so results can vary between operating systems.

What happens on division by zero in MariaDB?▼

Division by zero in MariaDB returns NULL by default rather than raising an error. An error occurs only when ERROR_ON_DIVISION_BY_ZERO is enabled in sql_mode, which is part of the default strict mode. The same applies to MOD with a zero divisor.

Should I use FLOAT or DECIMAL for money in MariaDB?▼

Use DECIMAL(p,s) for currency and anything needing exactness, since FLOAT and DOUBLE are approximate types where 0.1 + 0.2 does not equal 0.3. DECIMAL supports up to 38 digits of precision.

Is RAND() safe for generating security tokens in MariaDB?▼

RAND() is not cryptographically secure and should not be used for security tokens. RAND(N) with a constant seed is repeatable, which suits tests but not secrets, and RAND() is unsafe for statement-based replication.

What is the difference between TRUNCATE function and TRUNCATE TABLE?▼

TRUNCATE(X, D) is a numeric function that chops a number to D decimal places toward zero, while TRUNCATE TABLE is a DDL statement that empties a table. Despite the shared name, the two are unrelated.