如何为字符串列表中的每个元素添加引号

时间:2021-10-13 14:31:15

I have a postgresql sql that return a list o element stored in column :

我有一个postgresql sql返回列中存储的列表元素:

This is my sql :

这是我的sql:

SELECT quote_literal(value) AS cluster_values 
FROM process_configuration pc 
WHERE pc.parameter='CLUSTER_DATA_ELEMENT';

this request give me this value :

这个请求给了我这个价值:

cluster_values
----------------------------
'Gender,ResidenceAddress'

The value that I want to get is this : a quote on each element : 'Gender','ResidenceAddress'

我想得到的值是:每个元素的引用:'Gender','ResidenceAddress'

cluster_values
----------------------------
'Gender','ResidenceAddress'

Plz can someone help me fixing this thank you in advance

Plz有人可以帮我解决这个事先谢谢你

1 个解决方案

#1


2  

Use regexp_replace():

SELECT regexp_replace(value, '([^,]+)', '''\1''', 'g') AS cluster_values 
FROM process_configuration pc 
WHERE pc.parameter = 'CLUSTER_DATA_ELEMENT';

       cluster_values        
-----------------------------
 'Gender','ResidenceAddress'
(1 row) 

#1


2  

Use regexp_replace():

SELECT regexp_replace(value, '([^,]+)', '''\1''', 'g') AS cluster_values 
FROM process_configuration pc 
WHERE pc.parameter = 'CLUSTER_DATA_ELEMENT';

       cluster_values        
-----------------------------
 'Gender','ResidenceAddress'
(1 row)