PostgreSQL replace() Function

The PostgreSQL replace() function replaces all occurrences of a specified substring in a specified string with a new text and returns the result.

The PostgreSQL replace() function performs a case-insensitive match when searching for the substring replaced.

replace() Syntax

This is the syntax of the PostgreSQL replace() function:

replace(string, search_string, replacement)

Parameters

string

Required. The string to replace in.

search_string

Required. The substring to search for.

replacement

Required. The string to replace with.

Return value

The PostgreSQL function replace() return the string string with all occurrences of the substring search_string replaced by the string replacement.

replace() Examples

This example shows how to use the replace() function to replace some substring in a string:

SELECT
    replace('Hello World', 'World', 'Alice'),
    replace('Hello World', 'l', 'L'),
    replace('Hello World', 'w', 'w');
   replace   |   replace   |   replace
-------------+-------------+-------------
 Hello Alice | HeLLo WorLd | Hello World