PostgreSQL – Remove all special characters from a string

You can use regex_replace function to remove all special characters from a string in PostgreSQL database. Syntax is as shown below:

SELECT regexp_replace('string with special characters', '[^\w]+','','g');

Example:

SELECT regexp_replace('This - is%a $string', '[^\w]+','','g');
regex_replace
--------------
Thisisastring
See also  PostgreSQL - SELECT Statement