Home > Mobile >  PostgreSQL - How to match a value in a table where column has values with comma separation
PostgreSQL - How to match a value in a table where column has values with comma separation

Time:11-13

I have a table with the following field values:

enter image description here

I want to do a select where I can match a value from this keyword column. For example:

SELECT templateid FROM public.templates WHERE keyword='Yes'

I don't want to use LIKE because in the case one of the comma-separated values is Yessy then I will get a return and that's not correct.

It has to be an exact match of one of the comma separated values.

Any clue?

CodePudding user response:

You can convert the string into an array:

SELECT templateid 
FROM public.templates 
WHERE 'Yes' = any(string_to_array(keyword, ','))
  • Related