Skip to content

Commit

Permalink
Small updates, railroad TBA
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoolmer committed Jul 24, 2024
1 parent 4fa2c75 commit 727e4a9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions reference/sql/sample-by.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ When using `SAMPLE BY` with `FILL`, missing rows within the result set can be fi
However, this will only fill rows between existing data in the data set, and cannot be used to fill
rows outside of this range.

To fill outside the bounds of the existing data, you can specify a fill range using a `FROM-TO` clause.

#### Syntax

The resulting shape of the query can be specified using `FROM` and `TO`:
The resulting shape of the query is specified using `FROM` and `TO`:

```questdb-sql title='Pre-filling trip data' demo
SELECT pickup_datetime as t, count
Expand All @@ -91,7 +93,8 @@ Since there are no rows prior to 2009, these rows are filled automatically.
This is distinct from the `WHERE` clause with a simple rule of thumb -
`WHERE` controls what data flows in, `FROM-TO` controls what data flows out.

Both `FROM` and `TO` can be used in isolation to solely prefill or postfill data.
Both `FROM` and `TO` can be used in isolation to solely pre-fill or post-fill data. If `FROM` is not provided,
then the lower bound is the start of the dataset, aligned to calendar, and vice versa when `TO` is omitted.

#### `WHERE` clause optimisation

Expand All @@ -100,7 +103,7 @@ QuestDB will add one for you, matching the `FROM-TO` interval.

This means that the query will run optimally, and avoid touching data not relevant to the result.

Therefore, the prior query will be compiled into something equivalent to this:
Therefore, the prior query will be compiled into something similar to this:

```questdb-sql title='Pre-filling trip data with WHERE optimisation' demo
SELECT pickup_datetime as t, count
Expand All @@ -117,7 +120,7 @@ Here are the current limits to this feature.
- This syntax is not compatible with `FILL(PREV)` or `FILL(LINEAR)`.
- This syntax is for `ALIGN TO CALENDAR` only (default alignment).
- Any specified `OFFSET` will not be considered.
- This syntax is for non-keyed `SAMPLE BY` i.e only designated timestamp and aggregate columns.
- This syntax is for non-keyed `SAMPLE BY` i.e. only designated timestamp and aggregate columns.


## Fill options
Expand Down

0 comments on commit 727e4a9

Please sign in to comment.