3

I have got a table employer_entity with column tokens. This column is a varchar and it contains many tokens splitted by comma, for instance:

id | tokens
---|------------------
 1 | aaaaa,bbbbb,ccccc

Now I want to build a query that will check if tokens column contains the token aaaaa. Here is what I've got

select *
from employer_entity
where 'aaaaa'
in (string_to_array(employer_entity.tokens, ','))

But it throws an error

Array value must start with "{" or dimension information.

1 Answer 1

5

You're looking for the any operator, not the in operator:

SELECT *
FROM   employer_entity
WHERE  'aaaaa' = ANY(STRING_TO_ARRAY(employer_entity.tokens, ','))
1
  • SQL Error [42883]: ERROR: function string_to_array(text[], unknown) does not exist Commented Apr 3, 2023 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.