1

I am using PostgreSQL with Laravel 8.

In a Postgres table, I have one comma separated character varying column

enter image description here

I need those records from this table where value of this comma separated column is 43 OR 56 OR 252.

2
  • That is a really bad design decision. Do you have a chance to fix the broken data model before proceeding? Commented Sep 2, 2022 at 12:13
  • No, I can't change DB design Commented Sep 2, 2022 at 12:15

1 Answer 1

2

Storing comma separated values in a single column is a huge mistake to begin with. But if you can't change the data model, you can achieve what you want by converting the value into an array, then use the array overlaps operator && with the values you want to test for:

select *
from the_table
where string_to_array(bad_column, ',')::int[] && array[43, 56, 252];
Sign up to request clarification or add additional context in comments.

Comments

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.