PostgreSQL 18 reference · String Functions
PostgreSQL REPLACE() Function
Replace every occurrence of a substring with another string. The search is case-sensitive.
PostgreSQL 18
Syntax
replace(string, from, to)
Parameters
| Parameter | Description |
|---|---|
string |
The input text. |
from |
The text to find. |
to |
The replacement. |
Return value
Text.
Examples
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.
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
REPLACE()· SQLite
Related
TRANSLATE()· Replace single characters by position: each character in 'from' becomes the matching character in 'to', or is deleted.REGEXP_REPLACE()· Replace text matching a POSIX regular expression. Add the 'g' flag to replace every match, not just the first.- SQL String Functions · tutorial