select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / STRING FUNCTIONS AND OPERATORS

Removes the longest string containing only characters in characters (a space by default) from the start, end, or both ends (BOTH is the default) of string.

Signatures & examples

trim ( [ LEADING | TRAILING | BOTH ] [ characters text ] FROM string text ) → text
Removes the longest string containing only characters in characters (a space by default) from the start, end, or both ends (BOTH is the default) of string.
trim(both 'xyz' from 'yxTomxx') → Tom
trim ( [ LEADING | TRAILING | BOTH ] [ FROM ] string text [, characters text ] ) → text
This is a non-standard syntax for trim().
trim(both from 'yxTomxx', 'xyz') → Tom
trim ( [ LEADING | TRAILING | BOTH ] bytesremoved bytea FROM bytes bytea ) → bytea
Removes the longest string containing only bytes appearing in bytesremoved from the start, end, or both ends (BOTH is the default) of bytes.
trim('\x9012'::bytea from '\x1234567890'::bytea) → \x345678
trim ( [ LEADING | TRAILING | BOTH ] [ FROM ] bytes bytea, bytesremoved bytea ) → bytea
This is a non-standard syntax for trim().
trim(both from '\x1234567890'::bytea, '\x9012'::bytea) → \x345678
Version history 4
  1. PG 13 → 14changed
  2. PG 12 → 13changed
  3. PG 9.3 → 9.4changed
  4. PG 9.1 → 9.2changed

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source