In this PostgreSQL post explains how to use the PostgreSQL replace function with syntax and examples.
The PostgreSQL replace function replaces all occurrences of a specified string.
The syntax for the replace function in PostgreSQL is:
replace( string, from_substring, to_substring )
The source string.
The substring to find. All occurrences of from_substring found within string are replaced with to_substring.
The replacement substring. All occurrences of from_substring found within string are replaced with to_substring.
The replace function can be used in the following versions of PostgreSQL:
Let's look at some PostgreSQL replace function examples and explore how to use the replace function in PostgreSQL.
For example:
postgres=# SELECT replace('AODBA.com', 'AODBA', 'checkyoursite');
replace
-------------------
checkyoursite.com
(1 row)
postgres=# SELECT replace('AODBA.com', 'AODBA', 'checkyoursite');
replace
-------------------
AODBA.com
(1 row)
postgres=# SELECT replace('abc abc', 'a', 'B');
replace
---------
Bbc Bbc
(1 row)
postgres=# SELECT replace('abc abc', 'A', 'B');
replace
---------
abc abc
(1 row)