Jay Parker
Jay Parker

Reputation: 47

How can I remove special characters from my column

Have a table with 2 columns. Column a has records with non alpha such as:

aaa)
aab(
aac#
123!

column b is blank

Need a PostgreSQL function that can strip all non alpha characters and insert the changed values to column b.

So that the end result is

columna

aaa)
aab(
aac#
123!

columnb

aaa
aab
aac
123

I want to be able to call function with table name. Thanks for any help

Upvotes: 3

Views: 6113

Answers (1)

sagi
sagi

Reputation: 40481

You can use REGEXP_REPLACE() :

UPDATE YourTable t
set t.columnB = regexp_replace(t.columnA, '[^a-zA-Z0-9]', '', 'g')

This should update your table columnB with the content of columnA without the special characters

Upvotes: 5

Related Questions