I have the following table:
cs_id ; cs_values ; cs_desc
---------------------------
     1;    'a,b,c';   'one'
     2;      'd,a';   'two'
     3;      'a,c'; 'three'
The field "cs_valies" contains different comma separeted values. I would like to get all "cs_id" on lines that contain a certain value in "cs_values".
I used this expression:
SELECT
   cs_id,
   regexp_split_to_table(cs_values, '* , *') as splitted_value
WHERE
   splitted_value = 'a'
I have to questions:
WHERE-clause. Or has anyone an idea how to achieve this?Thanks everybody, I hope I am not missing something extremly evident.
Postgres does not like alias names in the WHERE-clause. Or has anyone an idea how to achieve this?
SELECT * 
FROM (
   SELECT 
      cs_id,
      regexp_split_to_table(cs_values, '* , *') as splitted_value
) t
WHERE
   splitted_value = 'a'
Does anyone have a better idea to solve the given problem?
Normalize your table and put the "comma separated list" into its own table with. This is a classical 1:n relation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With