Skip to content

Commit 8f57a4f

Browse files
authored
docs: update warehouse SQL (#3059)
1 parent 6aadb40 commit 8f57a4f

File tree

6 files changed

+73
-7
lines changed

6 files changed

+73
-7
lines changed

docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/alter-warehouse.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ ALTER WAREHOUSE <warehouse_name>
2323
[ WITH ] max_cluster_count = <nullable_unsigned_number>
2424
[ WITH ] min_cluster_count = <nullable_unsigned_number>
2525
[ WITH ] comment = '<string_literal>'
26+
27+
ALTER WAREHOUSE <warehouse_name> SET TAG <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' ... ]
28+
29+
ALTER WAREHOUSE <warehouse_name> UNSET TAG <tag_name> [ , <tag_name> ... ]
30+
31+
ALTER WAREHOUSE <warehouse_name> RENAME TO <new_name>
2632
```
2733

2834
| Parameter | Description |
@@ -46,6 +52,9 @@ The `SET` clause accepts the same options as [CREATE WAREHOUSE](create-warehouse
4652

4753
- `NULL` is valid for numeric options to reset them to `0`.
4854
- Supplying `SET` with no options raises an error.
55+
- `SET TAG` adds or updates one or more tags. Multiple tags can be set in a single statement separated by commas.
56+
- `UNSET TAG` removes one or more tags by their keys. Non-existent tag keys are silently ignored.
57+
- `RENAME TO` requires the warehouse to be suspended and uses the same naming rules as `CREATE`.
4958

5059
## Examples
5160

@@ -75,3 +84,12 @@ Disable auto-suspend:
7584
```sql
7685
ALTER WAREHOUSE my_wh SET auto_suspend = NULL;
7786
```
87+
88+
Manage tags:
89+
90+
```sql
91+
ALTER WAREHOUSE wh_hot SET TAG environment = 'production';
92+
ALTER WAREHOUSE wh_hot SET TAG environment = 'staging', owner = 'john', cost_center = 'eng';
93+
ALTER WAREHOUSE wh_hot UNSET TAG environment;
94+
ALTER WAREHOUSE wh_hot UNSET TAG environment, owner, cost_center;
95+
```

docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CREATE WAREHOUSE [ IF NOT EXISTS ] <warehouse_name>
2020
[ WITH ] max_cluster_count = <nullable_unsigned_number>
2121
[ WITH ] min_cluster_count = <nullable_unsigned_number>
2222
[ WITH ] comment = '<string_literal>'
23+
[ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] )
2324
```
2425

2526
| Parameter | Description |
@@ -38,6 +39,7 @@ CREATE WAREHOUSE [ IF NOT EXISTS ] <warehouse_name>
3839
| `MAX_CLUSTER_COUNT` | `NULL` or non-negative integer | `0` | Upper bound for auto-scaling clusters. `0` disables auto-scale. |
3940
| `MIN_CLUSTER_COUNT` | `NULL` or non-negative integer | `0` | Lower bound for auto-scaling clusters; should be ≤ `MAX_CLUSTER_COUNT`. |
4041
| `COMMENT` | String | Empty | Free-form text surfaced by `SHOW WAREHOUSES`. |
42+
| `TAG` | Key-value pairs: `TAG ( key1 = 'value1', key2 = 'value2' )` | None | Resource tags for categorization and organization (similar to AWS tags). Used for cost allocation, environment identification, or team ownership. |
4143

4244
- Options may appear in any order and may repeat (the later value wins).
4345
- `AUTO_SUSPEND`, `MAX_CLUSTER_COUNT`, and `MIN_CLUSTER_COUNT` accept `= NULL` to reset to `0`.
@@ -54,7 +56,8 @@ CREATE WAREHOUSE IF NOT EXISTS etl_wh
5456
auto_resume = FALSE
5557
max_cluster_count = 4
5658
min_cluster_count = 2
57-
comment = 'Nightly ETL warehouse';
59+
comment = 'Nightly ETL warehouse'
60+
TAG (environment = 'production', team = 'data-engineering', cost_center = 'analytics');
5861
```
5962

6063
This example creates a basic Small warehouse:

docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,44 @@ Warehouse-related SQL commands for Databend Cloud.
88
## General Rules
99

1010
- **Warehouse naming**: 3–63 characters, `A-Z`, `a-z`, `0-9`, and `-` only.
11-
- **Identifiers**: Bare identifiers may omit quotes when they contain no spaces or special characters; otherwise enclose with single quotes.
12-
- **Numeric parameters**: Accept integers or `NULL`. Supplying `NULL` resets the value to default (e.g., `AUTO_SUSPEND = NULL` equals `0`).
11+
- **Strings and identifiers**: Bare identifiers may omit quotes when they contain no spaces; otherwise enclose with single quotes. Grammar allows keywords or numeric/boolean literals as names, but runtime validation still applies.
12+
- **Numeric parameters**: `nullable_unsigned_number` / `nullable_signed_number` accept integers or `NULL`. Supplying `NULL` resets the value (for example, `AUTO_SUSPEND = NULL` equals `0`).
13+
- **Time parameters**: `QUERY_HISTORY` uses `YYYY-MM-DD HH:MM:SS` (UTC or explicit timezone). Missing fractional seconds are interpreted as whole seconds.
1314
- **Boolean parameters**: Only `TRUE`/`FALSE` are accepted.
14-
- **`WITH` keyword**: May appear before the entire option list or ahead of each option. Options are whitespace-separated.
15+
- **`WITH` keyword**: May appear before the entire option list or ahead of each option. Options are whitespace-separated; commas are not part of the grammar.
16+
17+
## Warehouse Management
18+
19+
Tags are key-value pairs that help categorize and organize warehouses, similar to AWS resource tags. They are commonly used for:
20+
21+
- **Cost allocation**: Track warehouse costs by team, project, or cost center
22+
- **Environment identification**: Mark warehouses as dev, staging, or production
23+
- **Team ownership**: Identify which team owns or manages a warehouse
24+
- **Custom metadata**: Add any arbitrary metadata for organizational purposes
25+
26+
Tag keys and values are arbitrary strings (enclosed in quotes if they contain spaces or special characters). Tags can be:
27+
- Added at warehouse creation time using `WITH TAG (key = 'value', ...)`
28+
- Updated or added later using `ALTER WAREHOUSE ... SET TAG key = 'value'`
29+
- Removed using `ALTER WAREHOUSE ... UNSET TAG key`
30+
31+
Tags are returned in API responses and visible through `SHOW WAREHOUSES`.
32+
33+
**Tag Limits:**
34+
- Maximum 10 tags per warehouse
35+
- Tag name (key) maximum length: 128 characters
36+
- Tag value maximum length: 256 characters
37+
38+
## Supported Statements
39+
40+
| Statement | Purpose | Notes |
41+
| ------------------- | ---------------------------- | ------------------------------------------------------------------- |
42+
| `CREATE WAREHOUSE` | Create a warehouse | Supports `IF NOT EXISTS` and option list |
43+
| `REPLACE WAREHOUSE` | Recreate a warehouse | Same semantics as `CREATE WAREHOUSE`, handy for overwriting configs |
44+
| `ALTER WAREHOUSE` | Suspend/resume/mutate/rename | `SUSPEND`/`RESUME`, `SET <options>`, or `RENAME TO <name>` |
45+
| `DROP WAREHOUSE` | Delete a warehouse | Optional `IF EXISTS` |
46+
| `USE WAREHOUSE` | Bind the current session | Validates existence only |
47+
| `SHOW WAREHOUSES` | List warehouses | Optional `LIKE` filter |
48+
| `QUERY_HISTORY` | Inspect query logs | Filter by warehouse, time range, limit |
1549

1650
## Warehouse Management
1751

docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/query-history.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ QUERY_HISTORY
2222
| Parameter | Description |
2323
|-----------|-------------|
2424
| `BY WAREHOUSE` | Optional. Filters logs to a specific warehouse. Empty names raise an error. |
25-
| `FROM` | Optional. Start timestamp for the query range. Format: `YYYY-MM-DD HH:MM:SS`. Defaults to 1 hour before `TO`. |
26-
| `TO` | Optional. End timestamp for the query range. Format: `YYYY-MM-DD HH:MM:SS`. Defaults to current time. |
25+
| `FROM` | Optional. Start timestamp for the query range. Format: `YYYY-MM-DD HH:MM:SS` (UTC or explicit timezone). Defaults to 1 hour before `TO`. |
26+
| `TO` | Optional. End timestamp for the query range. Format: `YYYY-MM-DD HH:MM:SS` (UTC or explicit timezone). Defaults to current time. |
2727
| `LIMIT` | Optional. Maximum number of records to return. Defaults to `10`. Must be a positive integer. |
2828

2929
## Output Columns

docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/replace-warehouse.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ REPLACE WAREHOUSE <warehouse_name>
2020
[ WITH ] max_cluster_count = <nullable_unsigned_number>
2121
[ WITH ] min_cluster_count = <nullable_unsigned_number>
2222
[ WITH ] comment = '<string_literal>'
23+
[ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] )
2324
```
2425

2526
| Parameter | Description |

docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Lists all warehouses visible to the current tenant.
1212
## Syntax
1313

1414
```sql
15-
SHOW WAREHOUSES [ LIKE '<pattern>' ]
15+
SHOW WAREHOUSES [ LIKE '<pattern>' ] [ <pattern_without_like> ]
1616
```
1717

1818
| Parameter | Description |
1919
|-----------|-------------|
2020
| `LIKE '<pattern>'` | Optional. Filters warehouse names using SQL `LIKE` semantics (`%` matches any sequence, `_` matches any single character). |
21+
| `<pattern_without_like>` | Optional. When `LIKE` is omitted but a literal follows, it is treated as `LIKE '<literal>'`. |
2122

2223
## Output Columns
2324

@@ -30,7 +31,10 @@ SHOW WAREHOUSES [ LIKE '<pattern>' ]
3031
| `auto_resume` | Whether auto-resume is enabled |
3132
| `min_cluster_count` | Minimum cluster count for auto-scaling |
3233
| `max_cluster_count` | Maximum cluster count for auto-scaling |
34+
| `role` | Warehouse role |
3335
| `comment` | User-defined comment |
36+
| `tags` | Warehouse tags as a JSON-formatted string |
37+
| `created_by` | Creator |
3438
| `created_on` | Creation timestamp |
3539

3640
## Examples
@@ -46,3 +50,9 @@ List warehouses matching a pattern:
4650
```sql
4751
SHOW WAREHOUSES LIKE '%prod%';
4852
```
53+
54+
Use a literal without `LIKE`:
55+
56+
```sql
57+
SHOW WAREHOUSES nightly_etl;
58+
```

0 commit comments

Comments
 (0)