sqlcmd.net validated sql reference
beginner string-processing MySQL MariaDB SQL Server PostgreSQL SQLite

Trim Whitespace From Text

Remove leading and trailing whitespace from string values with `TRIM`.

Docker-validated Not currently validation-green

Remove spaces around a value

Leading and trailing spaces are removed before the value is returned.

Rows loaded before the example query runs.
Setup
CREATE TABLE inputs (raw_name VARCHAR(50));

INSERT INTO
  inputs (raw_name)
VALUES
  ('  Ada  ');
Shared across supported engines.
SQL
SELECT
  TRIM(raw_name) AS cleaned_name
FROM
  inputs;
Returned rows for the shared example.
cleaned_name
Ada

This `TRIM` example returns the same cleaned string across engines.

Where this command helps.

  • cleaning imported text before comparisons
  • normalizing user-entered values that may include accidental spaces

What the command is doing.

TRIM is useful when cleaning user input, imported text, or inconsistent source data. It removes whitespace around the edges of a string while leaving the internal text unchanged.