Unnesting and reforming a big query array seems to destroy null
up vote
1
down vote
favorite
SELECT ARRAY(SELECT foo FROM UNNEST(CAST(NULL as ARRAY<STRING>)) as foo) is null
returns false
vs.
SELECT CAST(NULL as ARRAY<STRING>) is null
returns true
My specific situation is that I'd like to sort an array using
SELECT ARRAY(SELECT foo from UNNEST(bar) as foo Order by foo) as arr
and keep the array as null if it was originally null. I'm open to alternatives for sorting the array but preserving null (meaning I'm not hung up on my implementation).
sql
add a comment |
up vote
1
down vote
favorite
SELECT ARRAY(SELECT foo FROM UNNEST(CAST(NULL as ARRAY<STRING>)) as foo) is null
returns false
vs.
SELECT CAST(NULL as ARRAY<STRING>) is null
returns true
My specific situation is that I'd like to sort an array using
SELECT ARRAY(SELECT foo from UNNEST(bar) as foo Order by foo) as arr
and keep the array as null if it was originally null. I'm open to alternatives for sorting the array but preserving null (meaning I'm not hung up on my implementation).
sql
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
SELECT ARRAY(SELECT foo FROM UNNEST(CAST(NULL as ARRAY<STRING>)) as foo) is null
returns false
vs.
SELECT CAST(NULL as ARRAY<STRING>) is null
returns true
My specific situation is that I'd like to sort an array using
SELECT ARRAY(SELECT foo from UNNEST(bar) as foo Order by foo) as arr
and keep the array as null if it was originally null. I'm open to alternatives for sorting the array but preserving null (meaning I'm not hung up on my implementation).
sql
SELECT ARRAY(SELECT foo FROM UNNEST(CAST(NULL as ARRAY<STRING>)) as foo) is null
returns false
vs.
SELECT CAST(NULL as ARRAY<STRING>) is null
returns true
My specific situation is that I'd like to sort an array using
SELECT ARRAY(SELECT foo from UNNEST(bar) as foo Order by foo) as arr
and keep the array as null if it was originally null. I'm open to alternatives for sorting the array but preserving null (meaning I'm not hung up on my implementation).
sql
sql
asked Nov 7 at 20:32
Andrew Cassidy
1,377724
1,377724
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
An empty array is different from a NULL with an array type. An empty array is an array with no elements. That is what you get from the UNNEST(). So, the comparison to NULL is false.
The second is returning NULL typed as an array. This is equivalent to NULL, so the comparison is true.
Got it. I'm used to a world where any operation on a NULL would result in a NULL....
– Andrew Cassidy
Nov 7 at 21:16
This is still true. But an array with a null element is not itself null.
– Elliott Brossard
Nov 7 at 22:30
@ElliottBrossard . . . Arrays in BQ do not haveNULLelements. An empty array is notNULL.
– Gordon Linoff
Nov 7 at 22:32
Yes, that's right. I was trying to explain to the OP that operations can involve nulls (e.g. ARRAY_LENGTH applied to an array with a null element) but not result in null.
– Elliott Brossard
Nov 7 at 23:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
An empty array is different from a NULL with an array type. An empty array is an array with no elements. That is what you get from the UNNEST(). So, the comparison to NULL is false.
The second is returning NULL typed as an array. This is equivalent to NULL, so the comparison is true.
Got it. I'm used to a world where any operation on a NULL would result in a NULL....
– Andrew Cassidy
Nov 7 at 21:16
This is still true. But an array with a null element is not itself null.
– Elliott Brossard
Nov 7 at 22:30
@ElliottBrossard . . . Arrays in BQ do not haveNULLelements. An empty array is notNULL.
– Gordon Linoff
Nov 7 at 22:32
Yes, that's right. I was trying to explain to the OP that operations can involve nulls (e.g. ARRAY_LENGTH applied to an array with a null element) but not result in null.
– Elliott Brossard
Nov 7 at 23:03
add a comment |
up vote
2
down vote
accepted
An empty array is different from a NULL with an array type. An empty array is an array with no elements. That is what you get from the UNNEST(). So, the comparison to NULL is false.
The second is returning NULL typed as an array. This is equivalent to NULL, so the comparison is true.
Got it. I'm used to a world where any operation on a NULL would result in a NULL....
– Andrew Cassidy
Nov 7 at 21:16
This is still true. But an array with a null element is not itself null.
– Elliott Brossard
Nov 7 at 22:30
@ElliottBrossard . . . Arrays in BQ do not haveNULLelements. An empty array is notNULL.
– Gordon Linoff
Nov 7 at 22:32
Yes, that's right. I was trying to explain to the OP that operations can involve nulls (e.g. ARRAY_LENGTH applied to an array with a null element) but not result in null.
– Elliott Brossard
Nov 7 at 23:03
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
An empty array is different from a NULL with an array type. An empty array is an array with no elements. That is what you get from the UNNEST(). So, the comparison to NULL is false.
The second is returning NULL typed as an array. This is equivalent to NULL, so the comparison is true.
An empty array is different from a NULL with an array type. An empty array is an array with no elements. That is what you get from the UNNEST(). So, the comparison to NULL is false.
The second is returning NULL typed as an array. This is equivalent to NULL, so the comparison is true.
answered Nov 7 at 21:05
Gordon Linoff
746k33285390
746k33285390
Got it. I'm used to a world where any operation on a NULL would result in a NULL....
– Andrew Cassidy
Nov 7 at 21:16
This is still true. But an array with a null element is not itself null.
– Elliott Brossard
Nov 7 at 22:30
@ElliottBrossard . . . Arrays in BQ do not haveNULLelements. An empty array is notNULL.
– Gordon Linoff
Nov 7 at 22:32
Yes, that's right. I was trying to explain to the OP that operations can involve nulls (e.g. ARRAY_LENGTH applied to an array with a null element) but not result in null.
– Elliott Brossard
Nov 7 at 23:03
add a comment |
Got it. I'm used to a world where any operation on a NULL would result in a NULL....
– Andrew Cassidy
Nov 7 at 21:16
This is still true. But an array with a null element is not itself null.
– Elliott Brossard
Nov 7 at 22:30
@ElliottBrossard . . . Arrays in BQ do not haveNULLelements. An empty array is notNULL.
– Gordon Linoff
Nov 7 at 22:32
Yes, that's right. I was trying to explain to the OP that operations can involve nulls (e.g. ARRAY_LENGTH applied to an array with a null element) but not result in null.
– Elliott Brossard
Nov 7 at 23:03
Got it. I'm used to a world where any operation on a NULL would result in a NULL....
– Andrew Cassidy
Nov 7 at 21:16
Got it. I'm used to a world where any operation on a NULL would result in a NULL....
– Andrew Cassidy
Nov 7 at 21:16
This is still true. But an array with a null element is not itself null.
– Elliott Brossard
Nov 7 at 22:30
This is still true. But an array with a null element is not itself null.
– Elliott Brossard
Nov 7 at 22:30
@ElliottBrossard . . . Arrays in BQ do not have
NULL elements. An empty array is not NULL.– Gordon Linoff
Nov 7 at 22:32
@ElliottBrossard . . . Arrays in BQ do not have
NULL elements. An empty array is not NULL.– Gordon Linoff
Nov 7 at 22:32
Yes, that's right. I was trying to explain to the OP that operations can involve nulls (e.g. ARRAY_LENGTH applied to an array with a null element) but not result in null.
– Elliott Brossard
Nov 7 at 23:03
Yes, that's right. I was trying to explain to the OP that operations can involve nulls (e.g. ARRAY_LENGTH applied to an array with a null element) but not result in null.
– Elliott Brossard
Nov 7 at 23:03
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197380%2funnesting-and-reforming-a-big-query-array-seems-to-destroy-null%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown