EN VI

How to select array with null values in sql?

2024-03-13 14:30:04
How to select array with null values in sql?
id  column1
1   ['A']
2   ['A', 'B', 'C']
3   [null]

I'd like to select row 3, but trying

SELECT * FROM table WHERE CONTAINS(column1, null)

returns empty result. I'm lost as to why that's not selecting row 3. Help?

Solution:

I'll assume you are working in a PostgreSQL environment. Simply can do it like this:

SELECT * FROM table WHERE null = any(column1)

or if null equals to empty string, just change it correspondingly

SELECT * FROM table WHERE '' = any(column1)

See the documentation here for more

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login