postgresql - Postgres: Trim white space from array values -


my records in table follows:

id    column1  1   'record1'  2   ' record2'  3   ' record3a, record3b'  4   'record4a , record4b, record4c '  column1 type: text 

pre-defined array= {record1,record2,record3a}

while i'm checking values pre-defined array using && operator, of values missed because of delimiter space between unnecessary.

hence need first remove these space there in beginning or end (only) , string_to_array() result compared pre-defined array

use trim() remove leading trailing whitespace:

select string_to_array(trim(both ' ' regexp_replace(column1, '\s*,\s*', ',')), ',') yourtable 

Comments

Popular posts from this blog

Formatting string according to pattern without regex in php -

ios - Align baselines with characters in large line heights with Text Kit -

xcode - CocoaPod Storyboard error: -