Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery - filtering without losing 'null' values

I try to filter a database but unluckily I lose the 'null' values either way:

The Sample looks like

Name | City | Sold
Nike | NYC  | 15
null | SFO  | 20
Mega | SEA  | 10
null | null | 8
nike | CHI  | 12

I try to look for the data without Nike in any way written but when I go for

Select ...
where not lower(Name) contains "nike"

but then I find only

Mega | SEA | 10

and all the rows with null values for Name are gone as well. How can I prevent their deletion? Thanks

like image 652
Ilja Avatar asked Apr 28 '15 08:04

Ilja


People also ask

How do I filter null values in BigQuery?

The syntax is as follows: Select * from table_source where column is not NULL; If you want to read more about the where operator, please refer to the documentation. In addition if you want to replace the null values, you can use the IFNNULL() function.

What is coalesce in BigQuery?

COALESCE(expr[, ... ]) Description. Returns the value of the first non-null expression. The remaining expressions are not evaluated.

Can you join on null values BigQuery?

For example, if you replace NULL with the empty string (or the string "null" , or something else that doesn't occur elsewhere in your data), the join will work as you expect. You can even do this on the fly by using a subquery, at minimal performance cost.

What is NVL in BigQuery?

NVL Function in BigQuery The NVL function lets you replace null (returned as a blank) with a string in the results of a query. You can use following BigQuery built-in functions as an NVL alternative: BigQuery IFNULL as an NVL Alternative.


1 Answers

See this:

select * from 
(select string(NULL) as name,'SFO' as city, 20 as sold),
(select 'Nike' as name,'NYC' as city, 15 as sold),
where not lower(name) contains 'nike2' or name is null

returns

+-----+------+------+------+---+
| Row | name | city | sold |   |
+-----+------+------+------+---+
|   1 | null | SFO  |   20 |   |
|   2 | Nike | NYC  |   15 |   |
+-----+------+------+------+---+
like image 70
Pentium10 Avatar answered Oct 17 '22 20:10

Pentium10