Skip to content

Commit

Permalink
Add new functions for workspaces sql docs
Browse files Browse the repository at this point in the history
  • Loading branch information
estherk15 committed Dec 23, 2024
1 parent 8ffea00 commit 1db3ca6
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions content/en/logs/workspaces/sql_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ WHERE department = 'Sales' AND name LIKE 'J%' {{< /code-block >}} |
ELSE 'Standard Order'
END AS order_type
FROM orders {{< /code-block >}} |
| `WINDOW` | Performs performs a calculation across a set of table rows that are somehow related to the current row. | {{< code-block lang="sql" >}}SELECT

Check failure on line 42 in content/en/logs/workspaces/sql_reference.md

View workflow job for this annotation

GitHub Actions / vale

Vale.Repetition

'performs' is repeated!
timestamp,
service_name,
cpu_usage_percent,
AVG(cpu_usage_percent) OVER (PARTITION BY service_name ORDER BY timestamp ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS moving_avg_cpu
FROM
cpu_usage_data {{< /code-block >}} |
| Arithmetic Operations | Performs basic calculations using operators like `+`, `-`, `*`, `/`. | {{< code-block lang="sql" >}}SELECT price, tax, (price * tax) AS total_cost
FROM products {{< /code-block >}} |

Expand All @@ -60,7 +67,9 @@ The following SQL functions are supported:
| `upper(string s)` | string | Returns the string as uppercase. |
| `abs(numeric n)` | numeric | Returns the absolute value. |
| `coalesce(args a)` | typeof first non-null a OR null | Returns the first non-null value or null if all are null. |

| `cast(value AS type)` | type | Converts the given value to the specified data type. |
| `length(string s)` | integer | Returns the number of characters in the string. |
| `INTERVAL value unit` | interval | Represents a time duration specified in a given unit. |


{{% collapse-content title="Examples" level="h3" %}}
Expand Down Expand Up @@ -136,10 +145,34 @@ FROM accounts

### `COALESCE`
{{< code-block lang="sql" >}}
SELECT COALESCE(phone_number, email) AS contact_info
SELECT COALESCE(phone_number, email) AS contact_info
FROM users
{{< /code-block >}}

### `CAST`
{{< code-block lang="sql" >}}
SELECT
CAST(order_id AS VARCHAR) AS order_id_string,
'Order-' || CAST(order_id AS VARCHAR) AS order_label
FROM
orders
{{< /code-block >}}

### `LENGTH`
{{< code-block lang="sql" >}}
SELECT
customer_name,
LENGTH(customer_name) AS name_length
FROM
customers
{{< /code-block >}}

### `INTERVAL`
{{< code-block lang="sql" >}}
SELECT
TIMESTAMP '2023-10-01 10:00:00' + INTERVAL '30 days' AS future_date
{{< /code-block >}}

{{% /collapse-content %}}


Expand Down

0 comments on commit 1db3ca6

Please sign in to comment.