Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NULL sorting in BigQuery

Is there a way to specify the following in the order by statement in BigQuery, or do the equivalent?

SELECT * FROM books
ORDER BY books ASC (nulls first)

or:

SELECT * FROM books
ORDER BY books ASC (nulls last)

This would need to be within the item itself, not adding on a second item such as:

ORDER BY books IS NULL ASC, books ASC

Ideally, I'd like to apply it across an entire table (all queries for it) or something like that.

Here is this feature in Postgres: https://stackoverflow.com/a/9511492/651174

like image 805
David542 Avatar asked Oct 16 '25 15:10

David542


1 Answers

Since May 1st 2020, NULLS FIRST and NULLS LAST feature is available

https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#order_by_clause

Your example can be expressed as

SELECT * FROM books
ORDER BY books ASC NULLS FIRST

and

SELECT * FROM books
ORDER BY books ASC NULLS LAST
like image 59
Yun Zhang Avatar answered Oct 18 '25 17:10

Yun Zhang



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!