Skip to content

Commit 6de7047

Browse files
committed
Adding views section and DECIMAL storage size
1 parent 4807df6 commit 6de7047

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

documentation/schema-design-essentials.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ For timezone handling at query time, see
147147
| `LONG` | 64 bits | -9.2E18 to 9.2E18 |
148148
| `FLOAT` | 32 bits | Single precision IEEE 754 |
149149
| `DOUBLE` | 64 bits | Double precision IEEE 754 |
150+
| `DECIMAL` | 1-32 bytes | [Variable based on precision](/docs/query/datatypes/decimal/#storage) |
150151

151152
Choose the smallest type that fits your data to save storage.
152153

@@ -227,6 +228,31 @@ the view are instant regardless of base table size.
227228

228229
See [Materialized Views](/docs/concepts/materialized-views/) for details.
229230

231+
## Views
232+
233+
When query performance is acceptable and you don't need materialization, use views to abstract complex queries:
234+
235+
```questdb-sql
236+
CREATE VIEW recent_trades AS (
237+
SELECT * FROM trades
238+
WHERE timestamp > dateadd('d', -7, now())
239+
);
240+
```
241+
242+
Views can be parameterized using `DECLARE OVERRIDABLE`:
243+
244+
```questdb-sql
245+
CREATE VIEW trades_above AS (
246+
DECLARE OVERRIDABLE @min_price := 100
247+
SELECT * FROM trades WHERE price >= @min_price
248+
);
249+
250+
-- Override at query time
251+
DECLARE @min_price := 500 SELECT * FROM trades_above;
252+
```
253+
254+
See [Views](/docs/concepts/views/) for details.
255+
230256
## Common mistakes
231257

232258
### Using VARCHAR for categorical data

0 commit comments

Comments
 (0)