diff --git a/documentation/concepts/materialized-views.md b/documentation/concepts/materialized-views.md index 524253ee1..4ae5c248d 100644 --- a/documentation/concepts/materialized-views.md +++ b/documentation/concepts/materialized-views.md @@ -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; ``` diff --git a/documentation/ingestion/import-csv.md b/documentation/ingestion/import-csv.md index 801c4b431..bb6216456 100644 --- a/documentation/ingestion/import-csv.md +++ b/documentation/ingestion/import-csv.md @@ -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; ``` diff --git a/documentation/query/datatypes/geohashes.md b/documentation/query/datatypes/geohashes.md index 1738de610..c5ea9698c 100644 --- a/documentation/query/datatypes/geohashes.md +++ b/documentation/query/datatypes/geohashes.md @@ -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 diff --git a/documentation/query/functions/meta.md b/documentation/query/functions/meta.md index ef16533fb..832f56bb2 100644 --- a/documentation/query/functions/meta.md +++ b/documentation/query/functions/meta.md @@ -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 | diff --git a/documentation/query/operators/spatial.md b/documentation/query/operators/spatial.md index 1ae1d49b7..052612065 100644 --- a/documentation/query/operators/spatial.md +++ b/documentation/query/operators/spatial.md @@ -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: @@ -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 | diff --git a/documentation/query/sql/copy.md b/documentation/query/sql/copy.md index 89c07d474..2e1b92072 100644 --- a/documentation/query/sql/copy.md +++ b/documentation/query/sql/copy.md @@ -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; diff --git a/documentation/query/sql/create-mat-view.md b/documentation/query/sql/create-mat-view.md index 037b8ff91..a3e7fc378 100644 --- a/documentation/query/sql/create-mat-view.md +++ b/documentation/query/sql/create-mat-view.md @@ -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. @@ -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 @@ -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 | @@ -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/). @@ -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: @@ -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 | @@ -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'; ``` @@ -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: @@ -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 @@ -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; ``` @@ -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; ``` @@ -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; ``` diff --git a/documentation/query/sql/update.md b/documentation/query/sql/update.md index 07639bc6a..fd43a03eb 100644 --- a/documentation/query/sql/update.md +++ b/documentation/query/sql/update.md @@ -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" diff --git a/documentation/query/sql/where.md b/documentation/query/sql/where.md index 6b8ed6a46..3c5fe2356 100644 --- a/documentation/query/sql/where.md +++ b/documentation/query/sql/where.md @@ -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 | @@ -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 | @@ -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`. @@ -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. diff --git a/documentation/tutorials/influxdb-migration.md b/documentation/tutorials/influxdb-migration.md index 42debee0f..22d5365eb 100644 --- a/documentation/tutorials/influxdb-migration.md +++ b/documentation/tutorials/influxdb-migration.md @@ -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: