-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[DDSQL] DDSQL type and type literal docs #31252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ DDSQL is SQL for Datadog data. It implements several standard SQL operations, su | |
|
|
||
| This documentation covers the SQL support available and includes: | ||
| - [Syntax compatible with PostgreSQL](#syntax) | ||
| - [Data types](#data-types) | ||
| - [Type literals](#type-literals) | ||
| - [SQL functions](#functions) | ||
| - [Window functions](#window-functions) | ||
| - [JSON functions](#json-functions-and-operators) | ||
|
|
@@ -88,6 +90,62 @@ FROM employees {{< /code-block >}} | | |
| FROM products {{< /code-block >}} | | ||
| | `INTERVAL value unit` | interval | Represents a time duration specified in a given unit. Supported units:<br>- `milliseconds` / `millisecond`<br>- `seconds` / `second`<br>- `minutes` / `minute`<br>- `hours` / `hour`<br>- `days` / `day` | | ||
|
|
||
| ## Data types | ||
|
|
||
| DDSQL supports the following data types: | ||
|
|
||
| | Data Type | Description | | ||
| |-----------|-------------| | ||
| | `BIGINT` | 64-bit signed integers. | | ||
| | `BOOLEAN` | `true` or `false` values. | | ||
| | `DOUBLE` | Double-precision floating-point numbers. | | ||
| | `INTERVAL` | Time duration values. | | ||
| | `JSON` | JSON data. | | ||
| | `TIMESTAMP` | Date and time values. | | ||
| | `VARCHAR` | Variable-length character strings. | | ||
|
|
||
| ### Array types | ||
|
|
||
| All data types except `JSON` support array types. Arrays can contain multiple values of the same data type. | ||
|
|
||
| ## Type literals | ||
|
|
||
| DDSQL supports explicit type literals using the syntax `[TYPE] [value]`. | ||
|
|
||
| | Type | Syntax | Example | | ||
| |------|--------|---------| | ||
| | `BIGINT` | `BIGINT value` | `BIGINT 1234567` | | ||
| | `BOOLEAN` | `BOOLEAN value` | `BOOLEAN true` | | ||
| | `DOUBLE` | `DOUBLE value` | `DOUBLE 3.14159` | | ||
| | `INTERVAL` | `INTERVAL 'value unit'` | `INTERVAL '30 minutes'` | | ||
| | `JSON` | `JSON 'value'` | `JSON '{"key": "value", "count": 42}'` | | ||
| | `TIMESTAMP` | `TIMESTAMP 'value'` | `TIMESTAMP '2023-12-25 10:30:00'` | | ||
| | `VARCHAR` | `VARCHAR 'value'` | `VARCHAR 'hello world'` | | ||
|
|
||
| The type prefix can be omitted and the type is automatically inferred from the value. For example, `'hello world'` is inferred as `VARCHAR`, `123` as `BIGINT`, and `true` as `BOOLEAN`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider including some guidance on when to use the type prefix. It's not clear why users need this. |
||
|
|
||
| ### Array literals | ||
|
|
||
| Array literals use the syntax `ARRAY[value1, value2, ...]`. The array type is automatically inferred from the values. | ||
|
|
||
| {{< code-block lang="sql" >}} | ||
| SELECT ARRAY['apple', 'banana', 'cherry'] AS fruits; -- Inferred as VARCHAR array | ||
| SELECT ARRAY[1, 2, 3] AS numbers; -- Inferred as BIGINT array | ||
| SELECT ARRAY[true, false, true] AS flags; -- Inferred as BOOLEAN array | ||
| SELECT ARRAY[1.1, 2.2, 3.3] AS decimals; -- Inferred as DOUBLE array | ||
| {{< /code-block >}} | ||
|
|
||
| ### Example | ||
|
|
||
| {{< code-block lang="sql" >}} | ||
| -- Using type literals in queries | ||
| SELECT | ||
| VARCHAR 'Product Name: ' || name AS labeled_name, | ||
| price * DOUBLE 1.08 AS price_with_tax, | ||
| created_at + INTERVAL '7 days' AS expiry_date | ||
| FROM products | ||
| WHERE active = BOOLEAN true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit torn about including a where clause like this, which I think idiomatically should be written |
||
| {{< /code-block >}} | ||
|
|
||
| ## Functions | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
select array_agg(x) from (select cast('{"x":1}' as json) x union all select cast('{"x":2}' as json))seems to work fine?