string

TRIM

Removes matching characters from the start, end, or both sides of a string. Defaults to stripping spaces when no character set is supplied.

TRIM([LEADING|TRAILING|BOTH] [chars] FROM string)  |  TRIM(string)

Parameters / Modifiers

Parameter Purpose
LEADING Strip only from the left side
TRAILING Strip only from the right side
BOTH Default: strip from both ends
LTRIM / RTRIM Shortcut functions available in every dialect

Examples

SELECT TRIM('  hello  ');

Returns 'hello'

SELECT TRIM(BOTH '/' FROM '/api/v1/');

Returns 'api/v1'

SELECT LTRIM(RTRIM(username)) FROM users;

Portable double-sided trim in every dialect

SELECT TRIM(LEADING '0' FROM '000042');

Returns '42' — strip leading zeros

Dialect notes / Gotcha

TRIM() only removes spaces by default, not tabs or newlines — pass an explicit character set to remove whitespace. SQLite TRIM only accepts single-character sets, not multi-char strings like Postgres/MySQL.

Related functions

← All SQL functions · SQL cheat sheet · Window functions · PostgreSQL cheat sheet