|
| 1 | +--- |
| 2 | +title: SETTINGS |
| 3 | +--- |
| 4 | +import FunctionDescription from '@site/src/components/FunctionDescription'; |
| 5 | + |
| 6 | +<FunctionDescription description="Introduced or updated: v1.2.652"/> |
| 7 | + |
| 8 | +The SETTINGS clause configures specific settings that influence the execution behavior of the SQL statement it precedes. To view the available settings in Databend and their values, use [SHOW SETTINGS](../50-administration-cmds/03-show-settings.md). |
| 9 | + |
| 10 | +## Syntax |
| 11 | + |
| 12 | +```sql |
| 13 | +SETTINGS ( <setting> = <value> [, <setting> = <value>, ...] ) <statement> |
| 14 | +``` |
| 15 | + |
| 16 | +## Supported Statements |
| 17 | + |
| 18 | +The SETTINGS clause can be used with the following SQL statements: |
| 19 | + |
| 20 | +- [SELECT](01-query-select.md) |
| 21 | +- [INSERT](../10-dml/dml-insert.md) |
| 22 | +- [INSERT (multi-table)](../10-dml/dml-insert-multi.md) |
| 23 | +- [MERGE](../10-dml/dml-merge.md) |
| 24 | +- [`COPY INTO <table>`](../10-dml/dml-copy-into-table.md) |
| 25 | +- [`COPY INTO <location>`](../10-dml/dml-copy-into-location.md) |
| 26 | +- [UPDATE](../10-dml/dml-update.md) |
| 27 | +- [DELETE](../10-dml/dml-delete-from.md) |
| 28 | +- [CREATE TABLE](../00-ddl/01-table/10-ddl-create-table.md) |
| 29 | +- [EXPLAIN](../40-explain-cmds/explain.md) |
| 30 | + |
| 31 | +## Examples |
| 32 | + |
| 33 | +This example demonstrates how the SETTINGS clause can be used to adjust the timezone parameter in a SELECT query, impacting the displayed result of `now()`: |
| 34 | + |
| 35 | +```sql |
| 36 | +-- When no timezone is set, Databend defaults to UTC, so now() returns the current UTC timestamp |
| 37 | +SELECT timezone(), now(); |
| 38 | + |
| 39 | +┌─────────────────────────────────────────┐ |
| 40 | +│ timezone() │ now() │ |
| 41 | +│ String │ Timestamp │ |
| 42 | +├────────────┼────────────────────────────┤ |
| 43 | +│ UTC │ 2024-11-04 19:42:28.424925 │ |
| 44 | +└─────────────────────────────────────────┘ |
| 45 | + |
| 46 | +-- By setting the timezone to Asia/Shanghai, the now() function returns the local time in Shanghai, which is 8 hours ahead of UTC. |
| 47 | +SETTINGS (timezone = 'Asia/Shanghai') SELECT timezone(), now(); |
| 48 | + |
| 49 | +┌────────────────────────────────────────────┐ |
| 50 | +│ timezone() │ now() │ |
| 51 | +├───────────────┼────────────────────────────┤ |
| 52 | +│ Asia/Shanghai │ 2024-11-05 03:42:42.209404 │ |
| 53 | +└────────────────────────────────────────────┘ |
| 54 | + |
| 55 | +-- Setting the timezone to America/Toronto adjusts the now() output to the local time in Toronto, reflecting the Eastern Time Zone (UTC-5 or UTC-4 during daylight saving time). |
| 56 | +SETTINGS (timezone = 'America/Toronto') SELECT timezone(), now(); |
| 57 | + |
| 58 | +┌──────────────────────────────────────────────┐ |
| 59 | +│ timezone() │ now() │ |
| 60 | +│ String │ Timestamp │ |
| 61 | +├─────────────────┼────────────────────────────┤ |
| 62 | +│ America/Toronto │ 2024-11-04 14:42:48.353577 │ |
| 63 | +└──────────────────────────────────────────────┘ |
| 64 | +``` |
| 65 | + |
| 66 | +This example allows the COPY INTO operation to utilize up to 100 threads for parallel processing: |
| 67 | + |
| 68 | +```sql |
| 69 | +SETTINGS (max_threads = 100) COPY INTO ... |
| 70 | +``` |
0 commit comments