SLOPDB / DOCUMENTATION / CORE SQL FUNCTIONS

Core SQL functions

Function inventory verified against the supplied SlopDB source checkout e5e2eb2. Entries document implemented behavior, including compatibility placeholders and restrictions.

← Search all SQL functions · 30 documented names/forms in this family.

These are the native scalar functions. They work in expressions, predicates, prepared statements, and supported stored expressions. PostgreSQL overrides and MySQL mode can change the behavior of the same name; follow the dialect-specific references when connecting through those listeners.

Inputs, NULL, and comparisons

Function names are case-insensitive. Optional arguments are shown in brackets; ellipses mean repetition. NULL behavior is documented per entry. Conditional functions evaluate only the selected branch. Scalar MIN/MAX take two or more arguments; the one-argument form is a grouped aggregate. Comparisons follow the active text collation.

Native time modifiers

DATE, TIME, DATETIME, JULIANDAY, and STRFTIME accept supported ISO-like dates/times, the word now, or numeric Julian days. Modifiers apply left to right: start of day, start of month, start of year, utc, localtime, weekday N, and signed amounts of days, hours, minutes, seconds, months, or years. Here weekday N means the next matching weekday (Sunday=0), advancing seven days if already on that weekday. Calendar month/year arithmetic follows the native implementation rather than promising SQLite equivalence.

SELECT DATE('2026-01-15', 'start of month', '+1 month');

Conditional values

COALESCE(value, value, ...)

Returns selected value

Returns the first non-NULL argument; later arguments are not evaluated after a value is found. At least two arguments are required.

SELECT COALESCE(NULL, 'ready');
Source: sql/executor.go · e5e2eb2

IFNULL(value, fallback)

Returns selected value

Returns fallback only when value is NULL, evaluating only the selected argument.

SELECT IFNULL(NULL, 'ready');
Source: sql/executor.go · e5e2eb2

IIF(condition, when_true, when_false)

Returns selected value

Evaluates the condition and only the selected branch. A NULL condition selects the false branch.

SELECT IIF(2 > 1, 'yes', 'no');
Source: sql/executor.go · e5e2eb2

MAX(value, value, ...)

Returns selected value

With two or more scalar arguments, returns the smallest or largest value using active comparison rules. Any NULL argument makes the result NULL. One argument selects the grouped aggregate form.

SELECT MAX(3, 1, 2);
Source: sql/executor.go · e5e2eb2

MIN(value, value, ...)

Returns selected value

With two or more scalar arguments, returns the smallest or largest value using active comparison rules. Any NULL argument makes the result NULL. One argument selects the grouped aggregate form.

SELECT MIN(3, 1, 2);
Source: sql/executor.go · e5e2eb2

NULLIF(a, b)

Returns value or NULL

Returns NULL when a and b compare equal under the active comparison rules; otherwise returns a.

SELECT NULLIF(4, 4);
Source: sql/executor.go · e5e2eb2

Strings and binary values

HEX(value)

Returns TEXT

Returns uppercase hexadecimal input bytes. Numeric inputs are encoded from their text representation. Native NULL produces an empty string; MySQL-mode NULL remains NULL.

Numeric inputs currently retain native textual-byte conversion in MySQL mode too; this is not complete MySQL numeric HEX equivalence.

SELECT HEX('Go');
Source: sql/executor.go · e5e2eb2

INSTR(haystack, needle)

Returns INTEGER

Returns the one-based first match or zero when absent. Two BLOBs use byte positions; otherwise positions count Unicode code points. NULL propagates.

SELECT INSTR('slopdb', 'db');
Source: sql/executor.go · e5e2eb2

LENGTH(value)

Returns INTEGER

Counts Unicode code points in TEXT and bytes in BLOB. NULL returns NULL.

MySQL mode overrides LENGTH to count bytes; PostgreSQL uses its own text/bytea implementation.

SELECT LENGTH('slime');
Source: sql/executor.go · e5e2eb2

LOWER(text)

Returns TEXT

Changes letter case using Unicode-aware string conversion. NULL returns NULL.

SELECT LOWER('Slime');
Source: sql/executor.go · e5e2eb2

LTRIM(text [, characters])

Returns TEXT

Removes a set of characters from both ends, the left end, or the right end, respectively. The default character set is a space. NULL input or trim set returns NULL.

SQL TRIM([BOTH | LEADING | TRAILING] substring FROM text) is also parsed; that syntax removes repeated whole substrings.

SELECT LTRIM('  slime  ');
Source: sql/executor.go · e5e2eb2

QUOTE(value)

Returns TEXT

Formats a value as a SQL literal, including SQL NULL and escaped string quoting.

SELECT QUOTE('slime');
Source: sql/executor.go · e5e2eb2

REPLACE(text, search, replacement)

Returns TEXT

Replaces every literal occurrence. An empty search leaves the input unchanged; any NULL argument returns NULL.

SELECT REPLACE('slopdb', 'slop', 'go');
Source: sql/executor.go · e5e2eb2

RTRIM(text [, characters])

Returns TEXT

Removes a set of characters from both ends, the left end, or the right end, respectively. The default character set is a space. NULL input or trim set returns NULL.

SQL TRIM([BOTH | LEADING | TRAILING] substring FROM text) is also parsed; that syntax removes repeated whole substrings.

SELECT RTRIM('  slime  ');
Source: sql/executor.go · e5e2eb2

SUBSTR(value, start [, length])

Returns TEXT or BLOB

Slices TEXT by Unicode code point or BLOB by byte. Positions are one-based; negative starts count from the end. A negative length selects characters preceding the start.

Start zero reduces a positive requested length by one. PostgreSQL overrides negative-position/negative-length behavior.

SELECT SUBSTR('slopdb', 2, 3);
Source: sql/executor.go · e5e2eb2

TRIM(text [, characters])

Returns TEXT

Removes a set of characters from both ends, the left end, or the right end, respectively. The default character set is a space. NULL input or trim set returns NULL.

SQL TRIM([BOTH | LEADING | TRAILING] substring FROM text) is also parsed; that syntax removes repeated whole substrings.

SELECT TRIM('  slime  ');
Source: sql/executor.go · e5e2eb2

TYPEOF(value)

Returns TEXT

Returns a native diagnostic type label: null, integer, real, blob, or text. Other native value kinds currently fall through to text.

This is a diagnostic label, not a complete declaration or PostgreSQL type-name lookup.

SELECT TYPEOF(12);
Source: sql/executor.go · e5e2eb2

UPPER(text)

Returns TEXT

Changes letter case using Unicode-aware string conversion. NULL returns NULL.

SELECT UPPER('Slime');
Source: sql/executor.go · e5e2eb2

Numbers and conversion

ABS(number)

Returns numeric

Returns absolute numeric value, preserving integer or exact numeric representation where supported. NULL propagates; nonnumeric input and signed integer overflow fail.

MySQL and PostgreSQL sessions provide their own coercion and metadata rules.

SELECT ABS(-12);
Source: sql/executor.go · e5e2eb2

CAST(value AS type)

Returns target type

Converts to a supported SQL type with the active dialect’s conversion, precision, range, and length checks. NULL remains NULL.

Use SQL AS syntax, not CAST(value, type). PostgreSQL also supports :: casts. See SQL semantics and the protocol guides for type coverage.

SELECT CAST('42' AS INTEGER);
Source: sql/executor.go · e5e2eb2

RANDOM()

Returns INTEGER

Returns a nonnegative pseudo-random signed 64-bit integer. It is not a cryptographic random-byte generator.

PostgreSQL mode retains this native integer behavior; use RAND for a MySQL-style real result.

SELECT RANDOM();
Source: sql/executor.go · e5e2eb2

ROUND(number [, digits])

Returns numeric

Rounds a numeric value; digits defaults to zero. Native digits are clamped to 0 through 30. Integer/real inputs use floating-point rounding; exact DECIMAL inputs retain decimal arithmetic.

MySQL supports negative digit counts and different exact/approximate tie rules. PostgreSQL uses a separate numeric implementation.

SELECT ROUND(12.345, 2);
Source: sql/executor.go · e5e2eb2

Native date and time

DATE([timestring [, modifier, ...]])

Returns TEXT

Formats a parsed value as YYYY-MM-DD, HH:MM:SS, or YYYY-MM-DD HH:MM:SS. No argument, an empty string, or now reads the current UTC clock.

Numeric input is a Julian day, not Unix seconds. Invalid or NULL timestrings fail. These are native helpers, not complete SQLite/MySQL temporal emulations.

SELECT DATE('2026-01-02 03:04:05');
Source: sql/executor.go · e5e2eb2

DATETIME([timestring [, modifier, ...]])

Returns TEXT

Formats a parsed value as YYYY-MM-DD, HH:MM:SS, or YYYY-MM-DD HH:MM:SS. No argument, an empty string, or now reads the current UTC clock.

Numeric input is a Julian day, not Unix seconds. Invalid or NULL timestrings fail. These are native helpers, not complete SQLite/MySQL temporal emulations.

SELECT DATETIME('2026-01-02 03:04:05');
Source: sql/executor.go · e5e2eb2

JULIANDAY([timestring [, modifier, ...]])

Returns REAL

Returns the Julian-day number for the parsed time, with the same inputs and modifiers as native DATE.

SELECT JULIANDAY('2000-01-01 12:00:00');
Source: sql/executor.go · e5e2eb2

STRFTIME(format [, timestring [, modifier, ...]])

Returns TEXT

Formats a native time with %Y, %m, %d, %H, %M, %S, %w, %j, %s, and %f. Here %f is a three-digit millisecond field, not SQLite’s seconds-plus-fraction field.

Unknown percent escapes emit the following character. Supported modifiers are described above the entries.

SELECT STRFTIME('%Y-%m-%d', '2026-01-02');
Source: sql/executor.go · e5e2eb2

TIME([timestring [, modifier, ...]])

Returns TEXT

Formats a parsed value as YYYY-MM-DD, HH:MM:SS, or YYYY-MM-DD HH:MM:SS. No argument, an empty string, or now reads the current UTC clock.

Numeric input is a Julian day, not Unix seconds. Invalid or NULL timestrings fail. These are native helpers, not complete SQLite/MySQL temporal emulations.

SELECT TIME('2026-01-02 03:04:05');
Source: sql/executor.go · e5e2eb2

Compatibility placeholders

CHANGES()

Returns INTEGER

Currently returns the integer 0. This native compatibility placeholder does not expose actual affected-row counts or the generated row ID.

Use Go ExecResult.Changes/LastID or MySQL ROW_COUNT()/LAST_INSERT_ID() for actual execution information.

SELECT CHANGES();
Source: sql/executor.go · e5e2eb2

LAST_INSERT_ROWID()

Returns INTEGER

Currently returns the integer 0. This native compatibility placeholder does not expose actual affected-row counts or the generated row ID.

Use Go ExecResult.Changes/LastID or MySQL ROW_COUNT()/LAST_INSERT_ID() for actual execution information.

SELECT LAST_INSERT_ROWID();
Source: sql/executor.go · e5e2eb2

FULLTEXT_MATCH(column, search [, mode])

Returns REAL · requires session or schema setup

Returns the shared full-text relevance score using an appropriate FULLTEXT index. Index configuration, including tokenizer, normalization, stopwords, token bounds, and ranking, is persisted and reused across native, MySQL, and PostgreSQL sessions.

Create an articles table and a FULLTEXT index on body before running this example. MySQL MATCH/AGAINST is a syntax adapter over the same engine; see SQL semantics for index configuration.

SELECT id, FULLTEXT_MATCH(body, 'slime') AS score FROM articles;
Source: sql/fulltext_query.go · e5e2eb2
Function reference checked against engine source · e5e2eb2Edit the function reference ↗