PostgreSQL 18 reference · String Functions

PostgreSQL REPLACE() Function

Replace every occurrence of a substring with another string. The search is case-sensitive.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

replace(string, from, to)

Parameters

ParameterDescription
string The input text.
from The text to find.
to The replacement.

Return value

Text.

Examples

Replace characters
SELECT replace('2026-01-05', '-', '/') AS us_style;

Output

  us_style
------------
 2026/01/05
(1 row)

Run this on your computer — see “Get Started” for setup.

Make URL slugs
SELECT name, replace(lower(name), ' ', '-') AS slug
FROM products
LIMIT 2;

Output

       name        |       slug
-------------------+-------------------
 SQL for Beginners | sql-for-beginners
 Clean Code        | clean-code
(2 rows)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?