Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/concepts/materialized-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Specify a partitioning scheme larger than the sampling interval:

```questdb-sql
CREATE MATERIALIZED VIEW my_view AS (
SELECT timestamp, symbol, sum(amount) FROM trades SAMPLE BY 8h
SELECT timestamp, symbol, sum(amount) AS total_amount FROM trades SAMPLE BY 8h
) PARTITION BY DAY;
```

Expand Down
2 changes: 1 addition & 1 deletion documentation/ingestion/import-csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ TRUNCATE TABLE table_name;
or import into another empty table and then use `INSERT INTO SELECT`:

```questdb-sql
INSERT INTO table_name batch 100000
INSERT BATCH 100000 INTO table_name
SELECT * FROM other_table;
```

Expand Down
5 changes: 3 additions & 2 deletions documentation/query/datatypes/geohashes.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ use of `WHERE 1 != 1` means that no rows are inserted, only the table schema is
prepared:

```questdb-sql
CREATE TABLE new_table AS
(SELECT cast(null AS geohash(4c)) gh4c)
CREATE TABLE new_table AS (
SELECT cast(null AS geohash(4c)) gh4c
FROM source_table WHERE 1 != 1
)
```

Geohash types can be cast from higher to lower precision, but not from lower to
Expand Down
2 changes: 1 addition & 1 deletion documentation/query/functions/meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ table_columns('my_table');
| s | VARCHAR | false | 0 | false | 0 | false | false |

```questdb-sql title="Get designated timestamp column"
SELECT column, type, designated FROM table_columns('my_table') WHERE designated = true;
SELECT "column", type, designated FROM table_columns('my_table') WHERE designated = true;
```

| column | type | designated |
Expand Down
4 changes: 2 additions & 2 deletions documentation/query/operators/spatial.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The `within` operator can be used to filter results by geohash:
```questdb-sql
SELECT * FROM pos
WHERE g8c within(#ezz, #u33d8)
LATEST ON ts PARTITON BY uuid;
LATEST ON ts PARTITION BY uuid;
```

This yields the following results:
Expand All @@ -82,7 +82,7 @@ exist within a larger grid:
```questdb-sql
SELECT * FROM pos
WHERE g8c within(#u33)
LATEST ON ts PARTITON BY uuid;
LATEST ON ts PARTITION BY uuid;
```

| ts | device_id | g1c | g8c |
Expand Down
2 changes: 1 addition & 1 deletion documentation/query/sql/copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ WITH FORMAT PARQUET;
Check all recent exports:

```questdb-sql title="View export history"
SELECT ts, table, destination, status, rows_exported
SELECT ts, "table", destination, status, rows_exported
FROM sys.copy_export_log
WHERE ts > dateadd('d', -1, now())
ORDER BY ts DESC;
Expand Down
24 changes: 12 additions & 12 deletions documentation/query/sql/create-mat-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Refreshes incrementally after each base table transaction:
```questdb-sql
CREATE MATERIALIZED VIEW trades_hourly
REFRESH IMMEDIATE AS
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h;
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h;
```

Best for: Real-time dashboards where data freshness matters.
Expand All @@ -108,7 +108,7 @@ Checks for new data and refreshes on a timer schedule:
```questdb-sql
CREATE MATERIALIZED VIEW trades_hourly
REFRESH EVERY 10m AS
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h;
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h;
```

Every 10 minutes, QuestDB checks if the base table has new data and performs an
Expand All @@ -119,7 +119,7 @@ With start time and timezone:
```questdb-sql
CREATE MATERIALIZED VIEW trades_hourly
REFRESH EVERY 1h START '2025-01-01T00:00:00Z' TIME ZONE 'Europe/Berlin' AS
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h;
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h;
```

| Option | Description |
Expand All @@ -141,7 +141,7 @@ Refreshes only when explicitly triggered:
```questdb-sql
CREATE MATERIALIZED VIEW trades_hourly
REFRESH MANUAL AS
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h;
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h;
```

Trigger refresh with [`REFRESH MATERIALIZED VIEW`](/docs/query/sql/refresh-mat-view/).
Expand All @@ -155,7 +155,7 @@ Skips the initial full refresh on creation. Applies to any strategy:
```questdb-sql
CREATE MATERIALIZED VIEW trades_hourly
REFRESH IMMEDIATE DEFERRED AS
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h;
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h;
```

The view remains empty until:
Expand All @@ -173,7 +173,7 @@ define an in-flight time window that won't refresh until complete.
```questdb-sql
CREATE MATERIALIZED VIEW trades_daily
REFRESH PERIOD (LENGTH 1d TIME ZONE 'Europe/London' DELAY 2h) AS
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1d;
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1d;
```

| Option | Description |
Expand All @@ -191,7 +191,7 @@ Matches period to the `SAMPLE BY` interval:
```questdb-sql
CREATE MATERIALIZED VIEW trades_hourly
REFRESH PERIOD (SAMPLE BY INTERVAL) AS
SELECT timestamp, symbol, avg(price) FROM trades
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades
SAMPLE BY 1h ALIGN TO CALENDAR TIME ZONE 'Europe/London';
```

Expand All @@ -205,7 +205,7 @@ Combine `PERIOD` with `EVERY` or `MANUAL`:
```questdb-sql title="Period with timer refresh"
CREATE MATERIALIZED VIEW hourly_stats
REFRESH EVERY 15m PERIOD (LENGTH 1h DELAY 5m) AS
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h;
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h;
```

This configuration:
Expand All @@ -218,7 +218,7 @@ The `DELAY` allows late-arriving data to be included before the period closes.
```questdb-sql title="Period with manual refresh"
CREATE MATERIALIZED VIEW trades_daily
REFRESH MANUAL PERIOD (LENGTH 1d TIME ZONE 'UTC' DELAY 1h) AS
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1d;
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1d;
```

With `MANUAL`, refresh only occurs when you run
Expand Down Expand Up @@ -249,7 +249,7 @@ Specify storage partitioning with `PARTITION BY`:

```questdb-sql
CREATE MATERIALIZED VIEW trades_hourly AS (
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h
) PARTITION BY DAY;
```

Expand All @@ -268,7 +268,7 @@ Limit data retention with `TTL`:

```questdb-sql
CREATE MATERIALIZED VIEW trades_hourly AS (
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h
) PARTITION BY DAY TTL 7 DAYS;
```

Expand Down Expand Up @@ -355,7 +355,7 @@ Assign ownership to a user, group, or service account:
```questdb-sql
CREATE GROUP analysts;
CREATE MATERIALIZED VIEW trades_hourly AS (
SELECT timestamp, symbol, avg(price) FROM trades SAMPLE BY 1h
SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h
) OWNED BY analysts;
```

Expand Down
2 changes: 1 addition & 1 deletion documentation/query/sql/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ UPDATE book SET mid = (bid + ask)/2 WHERE symbol = 'AAPL';
```

```questdb-sql title="Update with subquery"
UPDATE spreads s SET s.spread = p.ask - p.bid FROM prices p WHERE s.symbol = p.symbol;
UPDATE spreads s SET spread = p.ask - p.bid FROM prices p WHERE s.symbol = p.symbol;
```

```questdb-sql title="Update with multiple joins"
Expand Down
16 changes: 8 additions & 8 deletions documentation/query/sql/where.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ QuestDB automatically recognizes strings formatted as ISO timestamp as a
![Flow chart showing the syntax of the WHERE clause with a timestamp comparison](/images/docs/diagrams/whereTimestampExact.svg)

```questdb-sql title="Timestamp equals date"
SELECT scores WHERE ts = '2010-01-12T00:02:26.000Z';
SELECT * FROM scores WHERE ts = '2010-01-12T00:02:26.000Z';
```

| ts | score |
Expand All @@ -245,7 +245,7 @@ SELECT scores WHERE ts = '2010-01-12T00:02:26.000Z';
| ... | ... |

```questdb-sql title="Timestamp equals timestamp"
SELECT scores WHERE ts = '2010-01-12T00:02:26.000000Z';
SELECT * FROM scores WHERE ts = '2010-01-12T00:02:26.000000Z';
```

| ts | score |
Expand Down Expand Up @@ -461,9 +461,9 @@ WHERE timestamp BETWEEN '2024-04-01' AND '2024-04-03'
LIMIT -1;
```

| symbol | side | price | amount | timestamp |
|--------|------|-----------|----------|-----------------------------|
| BTC-USD| sell | 65,464.14 | 0.05100764 | 2024-04-02T23:59:59.9947212 |
| symbol | side | price | amount | timestamp |
| ------- | ---- | --------- | ---------- | --------------------------- |
| BTC-USD | sell | 65,464.14 | 0.05100764 | 2024-04-02T23:59:59.9947212 |

The query pushes to the boundaries as far as is possible, all the way to: `2024-04-02T23:59:59.9947212`.

Expand All @@ -478,9 +478,9 @@ WHERE timestamp BETWEEN '2024-04-01' AND '2024-04-03T00:00:00.99'
LIMIT -1;
```

| symbol | side | price | amount | timestamp |
|---------|------|----------|------------|----------------------------------|
| ETH-USD | sell | 3,279.11 | 0.00881686 | 2024-04-03T00:00:00.988858Z |
| symbol | side | price | amount | timestamp |
| ------- | ---- | -------- | ---------- | --------------------------- |
| ETH-USD | sell | 3,279.11 | 0.00881686 | 2024-04-03T00:00:00.988858Z |

Even with fractional seconds, the boundary is inclusive.

Expand Down
2 changes: 1 addition & 1 deletion documentation/tutorials/influxdb-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ data arrives we recommend transforming it in QuestDB.
For example, if you query a table with several metrics:

```questdb-sql
SELECT * FROM diagnostics WHERE timestamp = '2016-01-01T00:00:00.000000Z' AND driver='Andy' AND name='truck_150')
SELECT * FROM diagnostics WHERE timestamp = '2016-01-01T00:00:00.000000Z' AND driver='Andy' AND name='truck_150'
```

Your result may be something like this:
Expand Down