0

I have a table like this

multi_id   |      value
------------------------------------
{V1,V2,V3} | PD1
{V4,V5}    | PD2 
{V6,V7}    | PD3 

Now I want the value where id = V2 and V7. For that I have written a query like

select * from some_table where multi_id && ‘{“V2”,“V7"}’;

This is giving me result as :

multi_id   |      value
------------------------------------
{V1,V2,V3} | PD1
{V6,V7}    | PD3 

but what I want is:

some_column   |      value
------------------------------------
V2            | PD1
V7            | PD3 

Any help would be greatly appreciated.

2 Answers 2

2

Use unnest:

select t.some_column, st.value
from unnest(array['V1','V7']) as t(some_column)
  join some_table st on t.some_column = any(st.multi_id);
Sign up to request clarification or add additional context in comments.

Comments

1

You can use unnest:

select t.id, t.value
from (
    select unnest(multi_id), value
    from table_name tn
) as t(id, value)
where t.id in ('V2', 'V7');

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.