0

How to find a matching range based on a given value x

For example, in column A, we have the value: {15-17,18-20,21-23}

The output expected for the x=16 should be 15-17 or x=21 should be 21-23

Any idea of the best way to achieve that ?

3
  • What data type is that column? Commented Jan 9, 2023 at 13:23
  • It is a string type Commented Jan 9, 2023 at 13:27
  • i think you should make a iteration on your string ;) Commented Jan 9, 2023 at 13:32

1 Answer 1

1

Try

select rangetext 
from unnest('{15-17,18-20,21-23}'::text[]) as t(rangetext)
where 16 between split_part(rangetext , '-', 1)::integer 
             and split_part(rangetext , '-', 2)::integer;
Sign up to request clarification or add additional context in comments.

1 Comment

Top thanks, I'll try that immediately !!

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.