VAAA
VAAA

Reputation: 15049

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

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?

Upvotes: 0

Views: 1361

Answers (1)

user330315
user330315

Reputation:

You can convert the string into an array:

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

Upvotes: 1

Related Questions