Skip to content

Commit 006ccb0

Browse files
committed
update sort docs
1 parent c04e21e commit 006ccb0

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

web/book/src/transforms/sort.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,32 @@ it).
9090

9191
## Nulls
9292

93+
At the moment, PRQL does not guarantee any position of null values when
94+
ordering. To be precise, they are not comparable to any other values, which
95+
means that an ordered array may contain nulls first, last, or at any position in
96+
between.
97+
98+
However, prql-compiler will emit `NULLS LAST` (or dialect equivalent) in all
99+
`ORDER BY` clauses, with intention to make query results deterministic across
100+
different engines. This behavior may change, see
101+
[issue #2622](https://github.com/PRQL/prql/issues/).
102+
103+
To enforce `NULLS FIRST` or `NULLS LAST` right now, the following workaround can
104+
be used:
105+
106+
```prql
107+
from artists
108+
sort {artist_id != null, artist_id} # nulls first
109+
```
110+
111+
```prql
112+
from artists
113+
sort {artist_id == null, artist_id} # nulls last
114+
```
115+
116+
<!--
117+
TODO:
118+
93119
PRQL defaults to `NULLS LAST` when compiling to SQL. Because databases have
94120
different defaults, the compiler emits this for all targets for which it's not a
95121
default{{footnote: except for MSSQL, which don't support this}}.
@@ -113,4 +139,4 @@ take 42
113139
114140
```admonish info
115141
Check out [DuckDB #7174](https://github.com/duckdb/duckdb/pull/7174) for a survey of various databases' implementations.
116-
```
142+
``` -->

0 commit comments

Comments
 (0)