1

I need to get the empty array as NULL in my result set:

 select id,name,
 case when type = [] then NULL 
 else type 
 end as type
from table

Here type is defined as array<string> I am getting error for the above.

3
  • try type = array()? Commented Apr 19, 2021 at 13:19
  • @mck nope didnt work , getting error Commented Apr 19, 2021 at 13:25
  • could you post the error message by editing your question? Commented Apr 19, 2021 at 13:27

1 Answer 1

1

Check size(type) = 0

   select t.id, t.name, 
          case when size(t.type) = 0 then NULL 
               else t.type 
           end as type
    from mytable t
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.