Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering out empty strings in Snowflake

I have a very simple task which is turning out to be impossible. I have a column that has strings but also has blanks where it supposed to be a word (those are not NULLs they are just empty strings). For example:

LastName1,
EmptyRow,
LastName2,
EmptyRow,
EmptyRow,
LastName3...

Since empty rows are not NULLs, IS NOT NULL function is not working.

In the end result, I just need to filter out all rows that actually have values in them and get rid of all the empty rows. Can someone please give a suggestion?

like image 331
Agnieshka Avatar asked Aug 24 '26 22:08

Agnieshka


2 Answers

You can filter out these records by applying LENGTH function to it.

WHERE LENGTH(TRIM(COL_NAME)) > 0
like image 156
Shantanu Kher Avatar answered Aug 27 '26 17:08

Shantanu Kher


If there is a mix of single spaces, no spaces and nulls, I uses something like this

WHERE COALESCE(TRIM( lastname ), '') <> ''
like image 35
Mike Gohl Avatar answered Aug 27 '26 15:08

Mike Gohl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!