### Install Dependencies Source: https://github.com/databendlabs/databend-docs/blob/main/README.md Run this command to install project dependencies before starting local development. ```bash yarn ``` -------------------------------- ### Clone and Start Iceberg Quick Start Environment Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/00-sql-reference/30-table-engines/02-iceberg.md Clone the Iceberg quick start repository and launch the necessary Docker services. Ensure Docker and Docker Compose are installed beforehand. ```bash git clone https://github.com/databendlabs/iceberg-quick-start.git cd iceberg-quick-start docker compose up -d ``` -------------------------------- ### Create Database Example Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/10-sql-commands/00-ddl/00-database/ddl-alter-database.md Example of creating a database before renaming it. ```sql CREATE DATABASE DATABEND ``` -------------------------------- ### Show Databases Example Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/10-sql-commands/00-ddl/00-database/ddl-alter-database.md Example of showing existing databases. ```sql SHOW DATABASES ``` -------------------------------- ### Launch MinIO Container Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/tutorials/operate-and-recover/bendsave.md Starts a MinIO container with specified access keys and ports. Ensure Docker is installed. ```bash docker run -d --name minio \ -e "MINIO_ACCESS_KEY=minioadmin" \ -e "MINIO_SECRET_KEY=minioadmin" \ -p 9000:9000 \ -p 9001:9001 \ minio/minio server /data \ --address :9000 \ --console-address :9001 ``` -------------------------------- ### Create and Insert Data for PIVOT Example Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/10-sql-commands/20-query-syntax/05-query-pivot.md Creates a 'monthly_sales' table and inserts sample data to demonstrate the PIVOT operation. This setup is required before applying PIVOT. ```sql -- Create monthly_sales table CREATE TABLE monthly_sales( empid INT, amount INT, month VARCHAR ); -- Insert sales data INSERT INTO monthly_sales VALUES (1, 10000, 'JAN'), (1, 400, 'JAN'), (2, 4500, 'JAN'), (2, 35000, 'JAN'), (1, 5000, 'FEB'), (1, 3000, 'FEB'), (2, 200, 'FEB'), (2, 90500, 'FEB'), (1, 6000, 'MAR'), (1, 5000, 'MAR'), (2, 2500, 'MAR'), (2, 9500, 'MAR'), (1, 8000, 'APR'), (1, 10000, 'APR'), (2, 800, 'APR'), (2, 4500, 'APR'); ``` -------------------------------- ### Setup Dependencies and Compile Databend Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/developer/20-community/00-contributor/00-building-from-source.md Navigate to the Databend directory, install necessary dependencies, and add Cargo's bin directory to your PATH. ```shell cd databend make setup -d export PATH=$PATH:~/.cargo/bin ``` -------------------------------- ### Example: Create Table, Roles, Users, Masking Policy, and Apply Policy Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/12-mask-policy/create-mask-policy.md Demonstrates the full lifecycle of creating and applying a masking policy, including table setup, role creation, user management, policy definition, and column association. ```sql -- Create a table and insert sample data CREATE TABLE user_info ( user_id INT, phone VARCHAR, email VARCHAR ); INSERT INTO user_info (user_id, phone, email) VALUES (1, '91234567', 'sue@example.com'); INSERT INTO user_info (user_id, phone, email) VALUES (2, '81234567', 'eric@example.com'); -- Create a role CREATE ROLE 'MANAGERS'; GRANT ALL ON *.* TO ROLE 'MANAGERS'; -- Create a user and grant the role to the user CREATE USER manager_user IDENTIFIED BY 'databend'; GRANT ROLE 'MANAGERS' TO 'manager_user'; -- Create a masking policy that expects an extra column CREATE MASKING POLICY contact_mask AS (contact_val nullable(string), phone_ref nullable(string)) RETURNS nullable(string) -> CASE WHEN current_role() IN ('MANAGERS') THEN contact_val WHEN phone_ref LIKE '91%' THEN contact_val ELSE '*********' END COMMENT = 'mask contact data with phone check'; -- Associate the masking policy with the 'email' column ALTER TABLE user_info MODIFY COLUMN email SET MASKING POLICY contact_mask USING (email, phone); -- Associate the masking policy with the 'phone' column ALTER TABLE user_info MODIFY COLUMN phone SET MASKING POLICY contact_mask USING (phone, phone); -- Query with the Root user SELECT user_id, phone, email FROM user_info ORDER BY user_id; ``` ```text user_id │ phone │ email │ Nullable(Int32) │ Nullable(String) │ Nullable(String) │ ─────────────────┼──────────────────┼──────────────────┤ 1 │ 91234567 │ sue@example.com │ 2 │ ********* │ ********* │ ``` -------------------------------- ### Databend Server Startup Information Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/developer/20-community/02-rfcs/20220721-new-logging.md This is an example of the information displayed when starting the Databend server with the new logging configuration. It includes version, log status, storage details, and connection information. ```shell Databend Server starting at xxxxxxx (took x.xs) Information version: v0.7.128-xxxxx logs: file: enabled dir=./databend/logs level=DEBUG stderr: disabled (set LOG_STDERR_ON=true to enable) storage: s3://endpoint=127.0.0.1:1090,bucket=test,root=/path/to/data metasrv: embed Connection MySQL: mysql://root@localhost:3307/xxxx clickhouse: clickhouse://root@localhost:9000/xxxx clickhouse (HTTP): http://root:@localhost:9001 Useful Links Documentation: https://docs.databend.com Looking for help: https://github.com/databendlabs/databend/discussions ``` -------------------------------- ### Example: Creating and Using Databases and Tables Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/00-database/ddl-use-database.md Demonstrates the workflow of creating databases, switching between them using the USE command, creating tables, inserting data, and querying data within the selected database. ```sql -- Create two databases CREATE DATABASE database1; CREATE DATABASE database2; -- Select and use "database1" as the current database USE database1; -- Create a new table "table1" in "database1" CREATE TABLE table1 ( id INT, name VARCHAR(50) ); -- Insert data into "table1" INSERT INTO table1 (id, name) VALUES (1, 'John'); INSERT INTO table1 (id, name) VALUES (2, 'Alice'); -- Query all data from "table1" SELECT * FROM table1; -- Switch to "database2" as the current database USE database2; -- Create a new table "table2" in "database2" CREATE TABLE table2 ( id INT, city VARCHAR(50) ); -- Insert data into "table2" INSERT INTO table2 (id, city) VALUES (1, 'New York'); INSERT INTO table2 (id, city) VALUES (2, 'London'); -- Query all data from "table2" SELECT * FROM table2; ``` -------------------------------- ### Install Databend Go Driver Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/developer/00-drivers/00-golang.md Use 'go get' to install the official Databend Go driver. Refer to the driver overview for DSN format and connection examples. ```bash go get github.com/databendlabs/databend-go ``` -------------------------------- ### Boundary Behavior Example - Moving Average Start Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/08-window-functions/rows-between.md Demonstrates how a moving average window frame adjusts at the beginning of a partition, showing how the window shrinks when fewer preceding rows are available. ```sql -- For row 1: ROWS BETWEEN 2 PRECEDING AND CURRENT ROW -- Actual window: CURRENT ROW only (no preceding rows) -- For row 2: ROWS BETWEEN 2 PRECEDING AND CURRENT ROW -- Actual window: 1 PRECEDING AND CURRENT ROW (only 1 preceding row exists) ``` -------------------------------- ### TIME_SLICE Example with DATE Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/time-slice.md Demonstrates using TIME_SLICE with a DATE input to get the start and end boundaries of 4-month slices. ```sql SELECT '2019-02-28'::DATE AS "DATE", TIME_SLICE("DATE", 4, 'MONTH', 'START') AS "start", TIME_SLICE("DATE", 4, 'MONTH', 'END') AS "end"; ``` -------------------------------- ### Create Products Table Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-count-distinct.md Sets up a sample 'products' table with product information for demonstrating aggregate functions. ```sql CREATE TABLE products ( id INT, name VARCHAR, category VARCHAR, price FLOAT ); ``` ```sql INSERT INTO products (id, name, category, price) VALUES (1, 'Laptop', 'Electronics', 1000), (2, 'Smartphone', 'Electronics', 800), (3, 'Tablet', 'Electronics', 600), (4, 'Chair', 'Furniture', 150), (5, 'Table', 'Furniture', 300); ``` -------------------------------- ### Example: Create, Drop, and UNDROP a database Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/10-sql-commands/00-ddl/00-database/undrop-database.md This example demonstrates the full lifecycle of creating a database, dropping it, and then successfully recovering it using the UNDROP DATABASE command. ```sql root@localhost:8000/default> CREATE DATABASE orders_2024; CREATE DATABASE orders_2024 0 row written in 0.014 sec. Processed 0 row, 0 B (0 row/s, 0 B/s) root@localhost:8000/default> DROP DATABASE orders_2024; DROP DATABASE orders_2024 0 row written in 0.012 sec. Processed 0 row, 0 B (0 row/s, 0 B/s) root@localhost:8000/default> UNDROP DATABASE orders_2024; UNDROP DATABASE orders_2024 0 row read in 0.011 sec. Processed 0 row, 0 B (0 row/s, 0 B/s) ``` -------------------------------- ### Get Array Element by Index Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/10-semi-structured-functions/1-array/index.md Use GET to retrieve an element from an array using its index. Example: GET([1,2,3], 1) returns 1. ```sql GET([1,2,3], 1) ``` -------------------------------- ### Start Metabase Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/guides/35-connect/02-visualization/metabase.md Run the Metabase JAR file to start the Metabase application. ```bash java -jar metabase.jar ``` -------------------------------- ### Create and Insert Data for JOIN Examples Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/10-sql-commands/20-query-syntax/04-query-join.md Sets up sample tables (vip_info, purchase_records, gift, sensor_readings, hvac_mode) and populates them with data for demonstrating JOIN operations. ```sql CREATE OR REPLACE TABLE vip_info (client_id INT, region VARCHAR); INSERT INTO vip_info VALUES (101, 'Toronto'), (102, 'Quebec'), (103, 'Vancouver'); CREATE OR REPLACE TABLE purchase_records (client_id INT, item VARCHAR, qty INT); INSERT INTO purchase_records VALUES (100, 'Croissant', 2000), (102, 'Donut', 3000), (103, 'Coffee', 6000), (106, 'Soda', 4000); CREATE OR REPLACE TABLE gift (gift VARCHAR); INSERT INTO gift VALUES ('Croissant'), ('Donut'), ('Coffee'), ('Soda'); -- ASOF 示例的物联网数据 CREATE OR REPLACE TABLE sensor_readings ( room VARCHAR, reading_time TIMESTAMP, temperature DOUBLE ); INSERT INTO sensor_readings VALUES ('LivingRoom', '2024-01-01 09:55:00', 22.8), ('LivingRoom', '2024-01-01 10:00:00', 23.1), ('LivingRoom', '2024-01-01 10:05:00', 23.3), ('LivingRoom', '2024-01-01 10:10:00', 23.8), ('LivingRoom', '2024-01-01 10:15:00', 24.0); CREATE OR REPLACE TABLE hvac_mode ( room VARCHAR, mode_time TIMESTAMP, mode VARCHAR ); INSERT INTO hvac_mode VALUES ('LivingRoom', '2024-01-01 09:58:00', 'Cooling'), ('LivingRoom', '2024-01-01 10:06:00', 'Fan'), ('LivingRoom', '2024-01-01 10:30:00', 'Heating'); ``` -------------------------------- ### Get Start of Week Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md Returns the timestamp set to the start of the week (Monday by default) for a given date or timestamp. ```sql TO_START_OF_WEEK('2024-06-04') ``` -------------------------------- ### CockroachDB Node Startup Information Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/developer/20-community/02-rfcs/20220721-new-logging.md This example shows the output when starting a single node of CockroachDB. It includes build information, web UI and SQL connection details, log directory, and cluster status. ```shell ./cockroach start-single-node CockroachDB node starting at 2022-07-21 06:56:04.36859988 +0000 UTC (took 0.7s) build: CCL v22.1.4 @ 2022/07/19 17:09:48 (go1.17.11) WebUI: http://xuanwo-work:8080 sql: postgresql://root@xuanwo-work:26257/defaultdb?sslmode=disable sql (JDBC): JDBC:postgresql://xuanwo-work:26257/defaultdb?sslmode=disable&user=root RPC client flags: ./cockroach --host=xuanwo-work:26257 --insecure logs: /tmp/cockroach-v22.1.4.linux-amd64/cockroach-data/logs temp dir: /tmp/cockroach-v22.1.4.linux-amd64/cockroach-data/cockroach-temp3237741659 external I/O path: /tmp/cockroach-v22.1.4.linux-amd64/cockroach-data/extern store[0]: path=/tmp/cockroach-v22.1.4.linux-amd64/cockroach-data storage engine: pebble clusterID: e1ab003d-7eba-48cd-b635-7a51f40269c2 status: restarted preexisting node nodeID: 1 ``` -------------------------------- ### Start Local Preview Source: https://github.com/databendlabs/databend-docs/blob/main/README.md Execute this command to start a local development server for previewing documentation changes. ```bash yarn run dev ``` -------------------------------- ### Fast addr2line Setup Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/developer/20-community/00-contributor/04-how-to-profiling.md Clone and build the `addr2line` repository to potentially speed up heap analysis from minutes to seconds. Replace the placeholder with your actual `addr2line` path. ```bash git clone https://github.com/gimli-rs/addr2line cd addr2line cargo b --examples -r cp ./target/release/examples/addr2line ``` -------------------------------- ### Get Start of Week (Default Sunday) Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/to-start-of-week.md Returns the start of the week for a given date or timestamp. Defaults to Sunday if mode is not specified. ```sql SELECT to_start_of_week('2023-11-12 09:38:18.165575'); ┌────────────────────────────────────────────────┐ │ to_start_of_week('2023-11-12 09:38:18.165575') │ ├────────────────────────────────────────────────┤ │ 2023-11-12 │ └────────────────────────────────────────────────┘ ``` -------------------------------- ### Get Array Element by Index (Alias) Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/10-semi-structured-functions/1-array/index.md ARRAY_GET is an alias for the GET function. Example: ARRAY_GET([1,2,3], 1) returns 1. ```sql ARRAY_GET([1,2,3], 1) ``` -------------------------------- ### Show Roles and Set Role Example Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/02-user/04-user-set-role.md Demonstrates how to view available roles, set an active role, and then verify the change by showing roles again. Ensure the role you are setting exists. ```sql SHOW ROLES; ┌───────────────────────────────────────────────────────┐ │ name │ inherited_roles │ is_current │ is_default │ ├───────────┼─────────────────┼────────────┼────────────┤ │ developer │ 0 │ false │ false │ │ public │ 0 │ false │ false │ │ writer │ 0 │ true │ true │ └───────────────────────────────────────────────────────┘ SET ROLE developer; SHOW ROLES; ┌───────────────────────────────────────────────────────┐ │ name │ inherited_roles │ is_current │ is_default │ ├───────────┼─────────────────┼────────────┼────────────┤ │ developer │ 0 │ true │ false │ │ public │ 0 │ false │ false │ │ writer │ 0 │ false │ true │ └───────────────────────────────────────────────────────┘ ``` -------------------------------- ### Calculate Character Code with ORD() Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/06-string-functions/ord.md Use the ORD() function to get the character code of a string. This example shows how to get the code for the character '2'. ```sql SELECT ORD('2') ``` -------------------------------- ### Create Products Table and Insert Data Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/10-semi-structured-functions/0-json/json-path-query-first.md Sets up a sample table named 'products' with 'name' and 'details' columns, then populates it with product information in JSON format. This is a prerequisite for demonstrating JSON path queries. ```sql CREATE TABLE products ( name VARCHAR, details VARIANT ); INSERT INTO products (name, details) VALUES ('Laptop', '{"brand": "Dell", "colors": ["Black", "Silver"], "price": 1200, "features": {"ram": "16GB", "storage": "512GB"}}'), ('Smartphone', '{"brand": "Apple", "colors": ["White", "Black"], "price": 999, "features": {"ram": "4GB", "storage": "128GB"}}'), ('Headphones', '{"brand": "Sony", "colors": ["Black", "Blue", "Red"], "price": 150, "features": {"battery": "20h", "bluetooth": "5.0"}}'); ``` -------------------------------- ### Start Debezium Server with Docker Compose Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/guides/40-load-data/02-load-db/debezium.md Use Docker Compose to start the debezium-server-databend service in detached mode. Ensure Docker and Docker Compose are installed. ```bash docker-compose up -d ``` -------------------------------- ### Install BendSQL using cargo-binstall Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/guides/35-connect/00-sql-clients/bendsql.md Use this command to install BendSQL if you have `cargo-binstall` set up. Ensure Rust and Cargo are installed first. ```bash cargo binstall bendsql ``` -------------------------------- ### Prepare demo objects for task pipeline Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/guides/40-load-data/05-continuous-data-pipelines/02-task.md Sets up a database, schema, table, and stage required for the data loading task example. ```sql -- Create a playground schema and target table CREATE DATABASE IF NOT EXISTS task_demo; USE task_demo; CREATE OR REPLACE TABLE sensor_events ( event_time TIMESTAMP, sensor_id INT, temperature DOUBLE, humidity DOUBLE ); -- Stage that will store the generated Parquet files CREATE OR REPLACE STAGE sensor_events_stage; ``` -------------------------------- ### Unquoted SQL Identifiers Examples Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/00-sql-reference/40-sql-identifiers.md Examples of valid unquoted identifiers in Databend. These start with a letter or underscore and can contain letters, underscores, numbers, or dollar signs. ```text mydatabend MyDatabend1 My$databend _my_databend ``` -------------------------------- ### Example: Create, Show, and Alter Network Policy and User Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/12-network-policy/ddl-create-policy.md Demonstrates creating a network policy with specific allowed and blocked IPs, then showing the created policy, creating a user, and finally associating the network policy with the user. ```sql -- Create a network policy CREATE NETWORK POLICY sample_policy ALLOWED_IP_LIST=('192.168.1.0/24') BLOCKED_IP_LIST=('192.168.1.99') COMMENT='Sample'; SHOW NETWORK POLICIES; Name |Allowed Ip List |Blocked Ip List|Comment | -------------+-------------------------+---------------+-----------+ sample_policy|192.168.1.0/24 |192.168.1.99 |Sample | -- Create a user CREATE USER sample_user IDENTIFIED BY 'databend'; -- Associate the network policy with the user ALTER USER sample_user WITH SET NETWORK POLICY='sample_policy'; ``` -------------------------------- ### Get Array Size Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/10-semi-structured-functions/1-array/index.md Use ARRAY_SIZE to get the number of elements in an array. The alias ARRAY_LENGTH can also be used. Example: ARRAY_SIZE([1,2,3]) returns 3. ```sql ARRAY_SIZE([1,2,3]) ``` -------------------------------- ### Create Table and Insert Sample Data Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-approx-count-distinct.md Sets up a table named 'user_events' and populates it with sample data for demonstration purposes. ```sql CREATE TABLE user_events ( id INT, user_id INT, event_name VARCHAR ); INSERT INTO user_events (id, user_id, event_name) VALUES (1, 1, 'Login'), (2, 2, 'Login'), (3, 3, 'Login'), (4, 1, 'Logout'), (5, 2, 'Logout'), (6, 4, 'Login'), (7, 1, 'Login'); ``` -------------------------------- ### Example of NOT LIKE Usage Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/06-string-functions/not-like.md Demonstrates filtering function names that start with 'tou' but do not end with '64'. ```sql +----------+------------+ | name | category | +----------+------------+ | touint16 | conversion | | touint32 | conversion | | touint8 | conversion | +----------+------------+ ``` -------------------------------- ### Create Table and Insert Data Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-min-if.md Sets up a sample table named 'project_budgets' with project budget data for demonstration purposes. ```sql CREATE TABLE project_budgets ( id INT, project_id INT, department VARCHAR, budget FLOAT ); INSERT INTO project_budgets (id, project_id, department, budget) VALUES (1, 1, 'HR', 1000), (2, 1, 'IT', 2000), (3, 1, 'Marketing', 3000), (4, 2, 'HR', 1500), (5, 2, 'IT', 2500); ``` -------------------------------- ### Get Start of Day Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md Returns the timestamp set to the beginning of the day (00:00:00) for a given date or timestamp. ```sql TO_START_OF_DAY('2024-06-04 12:30:45') ``` -------------------------------- ### RANGE BETWEEN CURRENT ROW and UNBOUNDED FOLLOWING Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/08-window-functions/range-between.md Example of a frame starting from the current row to the end of the partition. ```sql RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING ``` -------------------------------- ### Example: Managing Users, Roles, and Grants Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/02-user/22-show-grants.md Illustrates creating users and roles, granting roles to users, and then using SHOW GRANTS to inspect these assignments and object privileges. ```sql -- Create a new user CREATE USER 'user1' IDENTIFIED BY 'password'; ``` ```sql -- Create a new role CREATE ROLE analyst; ``` ```sql -- Grant the analyst role to the user GRANT ROLE analyst TO 'user1'; ``` ```sql -- Create a database CREATE DATABASE my_db; ``` ```sql -- Grant privileges on the database to the role GRANT OWNERSHIP ON my_db.* TO ROLE analyst; ``` ```sql -- List privileges granted to the user SHOW GRANTS FOR user1; ``` ```sql -- List privileges granted to the role SHOW GRANTS FOR ROLE analyst; ``` ```sql -- List privileges granted on the database SHOW GRANTS ON DATABASE my_db; ``` ```sql -- Lists all users and roles that have been directly granted role_name. -- This command displays only the direct grantees of role_name. -- This means it lists users and roles that have explicitly received the role through a GRANT ROLE role_name TO statement. -- It does not show users or roles that acquire role_name indirectly via role hierarchies or inheritance. SHOW GRANTS OF ROLE analyst ``` ```sql SHOW GRANTS ON MASKING POLICY email_mask; ``` ```sql -- Inspect row access policy privileges SHOW GRANTS ON ROW ACCESS POLICY rap_region; ``` -------------------------------- ### Example: Listing User and Role Grants Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/20-sql-functions/17-table-functions/show-grants.md This example demonstrates creating a user and role, granting permissions, and then using SHOW_GRANTS to list authorizations for the user, role, and a stage. ```sql -- 创建新用户 CREATE USER 'user1' IDENTIFIED BY 'password'; ``` ```sql -- 创建新角色 CREATE ROLE analyst; ``` ```sql -- 将 analyst 角色授予用户 GRANT ROLE analyst TO 'user1'; ``` ```sql -- 创建 stage CREATE STAGE my_stage; ``` ```sql -- 将 stage 上的权限授予角色 GRANT READ ON STAGE my_stage TO ROLE analyst; ``` ```sql -- 列出用户的授权 SELECT * FROM SHOW_GRANTS('user', 'user1'); ``` ```sql -- 列出授予角色的权限 SELECT * FROM SHOW_GRANTS('role', 'analyst'); ``` ```sql -- 列出授予 stage 的权限 SELECT * FROM SHOW_GRANTS('stage', 'my_stage'); ``` -------------------------------- ### RANGE BETWEEN UNBOUNDED PRECEDING and CURRENT ROW Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/08-window-functions/range-between.md Example of a frame starting from the beginning of the partition up to the current row. ```sql RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ``` -------------------------------- ### Create Table and Insert Sample Data Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-quantile-disc.md Sets up a table named 'salary_data' and populates it with sample salary information for demonstration purposes. ```sql CREATE TABLE salary_data ( id INT, employee_id INT, salary FLOAT ); INSERT INTO salary_data (id, employee_id, salary) VALUES (1, 1, 50000), (2, 2, 55000), (3, 3, 60000), (4, 4, 65000), (5, 5, 70000); ``` -------------------------------- ### Get command output Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/guides/20-self-hosted/02-deployment/02-production/70-metasrv-cli-api.md Example output for the `kvapi::get` command, showing the state of the requested key. ```json { "seq": 23, "meta": null, "data": [ 98, 97, 114 ] } ``` -------------------------------- ### Example Webhook Notification Integration Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/16-notification/01-ddl-create-notification.md This example demonstrates creating a notification integration named 'SampleNotification' of type 'webhook'. It is enabled and configured to send notifications to a specified URL using GET method and a bearer token. ```sql CREATE NOTIFICATION INTEGRATION IF NOT EXISTS SampleNotification type = webhook enabled = true webhook = (url = 'https://example.com', method = 'GET', authorization_header = 'bearer auth') ``` -------------------------------- ### Create Table and Show Fields Example Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/01-table/show-fields.md This example demonstrates creating a table named 'books' and then using SHOW FIELDS to inspect its columns. The output shows the field name, type, nullability, default values, and extra information. ```sql CREATE TABLE books ( price FLOAT Default 0.00, pub_time DATETIME Default '1900-01-01', author VARCHAR ); SHOW FIELDS FROM books; ``` -------------------------------- ### Create Table, Stream, and Insert Data Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/20-query-syntax/with-stream-hints.md Sets up a table and a stream for demonstration purposes, then inserts initial data. ```sql CREATE TABLE t1(a int); CREATE STREAM s ON TABLE t1; INSERT INTO t1 values(1); INSERT INTO t1 values(2); ``` -------------------------------- ### Create Sales Table Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/20-sql-functions/08-window-functions/rows-between.md Sets up a sample 'sales' table with date, product, and amount columns for demonstrating window functions. ```sql CREATE OR REPLACE TABLE sales ( sale_date DATE, product VARCHAR(20), amount DECIMAL(10,2) ); INSERT INTO sales VALUES ('2024-01-01', 'A', 100.00), ('2024-01-02', 'A', 150.00), ('2024-01-03', 'A', 200.00), ('2024-01-04', 'A', 250.00), ('2024-01-05', 'A', 300.00), ('2024-01-01', 'B', 50.00), ('2024-01-02', 'B', 75.00), ('2024-01-03', 'B', 100.00), ('2024-01-04', 'B', 125.00), ('2024-01-05', 'B', 150.00); ``` -------------------------------- ### Get Start of Minute Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md Returns the timestamp set to the beginning of the minute (e.g., 12:30:00) for a given date or timestamp. ```sql TO_START_OF_MINUTE('2024-06-04 12:30:45') ``` -------------------------------- ### Create Example Table and Insert Data Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/10-sql-commands/10-dml/dml-copy-into-location.md Sets up a sample table named 'canadian_city_population' and populates it with data for use in subsequent examples. ```sql -- 创建示例表 CREATE TABLE canadian_city_population ( city_name VARCHAR(50), population INT ); -- 插入示例数据 INSERT INTO canadian_city_population (city_name, population) VALUES ('Toronto', 2731571), ('Montreal', 1704694), ('Vancouver', 631486), ('Calgary', 1237656), ('Ottawa', 934243), ('Edmonton', 972223), ('Quebec City', 542298), ('Winnipeg', 705244), ('Hamilton', 536917), ('Halifax', 403390); ``` -------------------------------- ### Get Start of Hour Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md Returns the timestamp set to the beginning of the hour (e.g., 12:00:00) for a given date or timestamp. ```sql TO_START_OF_HOUR('2024-06-04 12:30:45') ``` -------------------------------- ### Create and Describe Table Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/01-table/50-describe-table.md This example demonstrates creating a table with specific column types and default values, followed by describing its structure to view the defined columns. ```sql CREATE TABLE books ( price FLOAT Default 0.00, pub_time DATETIME Default '1900-01-01', author VARCHAR ); DESC books; ``` -------------------------------- ### Get Unique Array Elements (Alias) Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/10-semi-structured-functions/1-array/index.md ARRAY_UNIQUE is an alias for ARRAY_DISTINCT. Example: ARRAY_UNIQUE([1,2,2,3]) results in [1,2,3]. ```sql ARRAY_UNIQUE([1,2,2,3]) ``` -------------------------------- ### Create and Insert Data for LISTAGG Example Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-listagg.md Sets up a sample 'orders' table and populates it with data to demonstrate the LISTAGG function. ```sql CREATE TABLE orders ( customer_id INT, product_name VARCHAR ); INSERT INTO orders (customer_id, product_name) VALUES (1, 'Laptop'), (1, 'Mouse'), (1, 'Laptop'), (2, 'Phone'), (2, 'Headphones'); ``` -------------------------------- ### Run Kafka Docker Container Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/tutorials/ingest-and-stream/kafka-bend-ingest-kafka.md Starts a Kafka Docker container on port 9092. Ensure Docker is installed and running. ```shell docker run -d \ --name kafka \ -p 9092:9092 \ apache/kafka:latest ``` -------------------------------- ### Full Example: Ngram Index for Log Analysis Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/guides/55-performance/ngram-index.md A comprehensive example showing table creation for articles, setting up an Ngram index with gram_size=3, verifying index creation, inserting diverse data, and performing a LIKE search. It also includes EXPLAIN to verify index usage and performance metrics. ```sql -- 为应用程序日志创建表 CREATE TABLE t_articles ( id INT, content STRING ); -- 创建一个 n-gram 索引,分词长度为 3 CREATE NGRAM INDEX ngram_idx_content ON t_articles(content) gram_size = 3; -- 验证索引创建 SHOW INDEXES; ``` ```sql ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ name │ type │ original │ definition │ created_on │ updated_on │ ├───────────────────┼────────┼──────────┼──────────────────────────────────┼────────────────────────────┼─────────────────────┤ │ ngram_idx_content │ NGRAM │ │ t_articles(content)gram_size='3' │ 2025-05-13 01:02:58.598409 │ NULL │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` ```sql -- 插入测试数据:995 行不相关数据 + 5 行目标数据 INSERT INTO t_articles SELECT number, CONCAT('Random text number ', number) FROM numbers(995); INSERT INTO t_articles VALUES (1001, 'The silence was deep and complete'), (1002, 'They walked in silence through the woods'), (1003, 'Silence fell over the room'), (1004, 'A moment of silence was observed'), (1005, 'In silence, they understood each other'); -- 使用模式匹配进行搜索 SELECT id, content FROM t_articles WHERE content LIKE '%silence%'; -- 验证索引使用情况 EXPLAIN SELECT id, content FROM t_articles WHERE content LIKE '%silence%'; ``` ```sql -[ EXPLAIN ]----------------------------------- TableScan ├── table: default.default.t_articles ├── output columns: [id (#0), content (#1)] ├── read rows: 5 ├── read size: < 1 KiB ├── partitions total: 2 ├── partitions scanned: 1 ├── pruning stats: [segments: , blocks: ] ├── push downs: [filters: [is_true(like(t_articles.content (#1), '%silence%'))], limit: NONE] └── estimated rows: 15.62 ``` -------------------------------- ### Start Databend Instance with Docker Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/tutorials/getting-started/connect-to-databend-bendsql.md Launches a Databend instance locally in a Docker container. Ensure Docker is installed and running. ```bash docker run -d --name databend \ -e QUERY_DEFAULT_USER=eric \ -e QUERY_DEFAULT_PASSWORD=abc123 \ -p 3307:3307 -p 8000:8000 -p 8124:8124 -p 8900:8900 \ datafuselabs/databend:nightly ``` -------------------------------- ### Get Start of Year Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md Returns the timestamp set to the first day of the year (e.g., 2024-01-01) for a given date or timestamp. ```sql TO_START_OF_YEAR('2024-06-04') ``` -------------------------------- ### Create Table and Insert Data Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-covar-pop.md Sets up a sample table 'product_sales' and populates it with data for demonstrating the COVAR_POP function. ```sql CREATE TABLE product_sales ( id INT, product_id INT, units_sold INT, revenue FLOAT ); INSERT INTO product_sales (id, product_id, units_sold, revenue) VALUES (1, 1, 10, 1000), (2, 2, 20, 2000), (3, 3, 30, 3000), (4, 4, 40, 4000), (5, 5, 50, 5000); ``` -------------------------------- ### POST /v1/query (Session Examples) Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/developer/10-apis/http.md Demonstrates how to use session settings, such as specifying a database and configuring query execution parameters like max threads and memory usage. ```APIDOC ## POST /v1/query (Session Examples) ### Description Using Session Settings to configure query execution. ### Method POST ### Endpoint `/v1/query` ### Parameters #### Request Body - **sql** (string) - Required - The SQL statement to execute. - **session** (object) - Optional - Session configuration. - **database** (string) - Optional - The default database to use for the session. - **settings** (object) - Optional - Key-value pairs for session settings. - **max_threads** (string) - Optional - Maximum number of threads to use for query execution. - **max_memory_usage** (string) - Optional - Maximum memory usage allowed for the query. #### Request Example ```bash curl -u "user:password" \ --request POST \ 'https:///v1/query/' \ --header 'Content-Type: application/json' \ --header 'X-DATABEND-WAREHOUSE: ' \ --data-raw '{ "sql": "SELECT * FROM my_table", "session": { "database": "production", "settings": { "max_threads": "4", "max_memory_usage": "10737418240" } } }' ``` ``` -------------------------------- ### Get Start of Quarter Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md Returns the timestamp set to the first day of the quarter (e.g., 2024-04-01) for a given date or timestamp. ```sql TO_START_OF_QUARTER('2024-06-04') ``` -------------------------------- ### Get Start of Month Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md Returns the timestamp set to the first day of the month (e.g., 2024-06-01) for a given date or timestamp. ```sql TO_START_OF_MONTH('2024-06-04') ``` -------------------------------- ### BEGIN Syntax Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/14-transaction/begin.md The basic syntax for starting a transaction. ```sql BEGIN [ TRANSACTION ] ``` -------------------------------- ### ARRAY_GENERATE_RANGE Function Example Source: https://github.com/databendlabs/databend-docs/blob/main/pdf/docs.databend.en-sql.txt Generates an array of numbers within a specified range. Supports start, stop, and step values. ```sql SELECT ARRAY_GENERATE_RANGE(1, 10, 2); -- returns [1, 3, 5, 7, 9] ``` -------------------------------- ### Create and Insert Data into a Table Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/16-system-functions/fuse_snapshot.md Sets up a sample table and populates it with data for snapshot retrieval. ```sql CREATE TABLE mytable(a int, b int) CLUSTER BY(a+1); INSERT INTO mytable VALUES(1,1),(3,3); INSERT INTO mytable VALUES(2,2),(5,5); INSERT INTO mytable VALUES(4,4); ``` -------------------------------- ### RANGE BETWEEN CURRENT ROW and value FOLLOWING Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/08-window-functions/range-between.md Example of a frame starting from the current row up to a specified interval after the current row. ```sql RANGE BETWEEN CURRENT ROW AND INTERVAL '7' DAY FOLLOWING ``` -------------------------------- ### Set Up Table and Ownership Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/guides/56-security/data-protection/index.md Grant database creation privileges to a role, then create a table as that role. Ownership is automatically assigned. ```sql -- Run as account_admin GRANT CREATE DATABASE ON *.* TO ROLE data_engineer; -- Switch to data_engineer SET ROLE data_engineer; CREATE DATABASE ecommerce; CREATE TABLE ecommerce.orders ( order_id INT, customer_name STRING, phone STRING, region STRING, amount DECIMAL(10,2), created_at TIMESTAMP ); INSERT INTO ecommerce.orders VALUES (1, 'Alice', '13812345678', 'APAC', 299.00, '2025-01-15 10:00:00'), (2, 'Bob', '14987654321', 'EMEA', 150.00, '2025-01-16 11:00:00'), (3, 'Charlie', '13698765432', 'APAC', 520.00, '2025-01-17 09:30:00'), (4, 'Diana', '15012349876', 'AMER', 89.00, '2025-01-18 14:00:00'); ``` -------------------------------- ### RANGE BETWEEN value PRECEDING and CURRENT ROW Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/08-window-functions/range-between.md Example of a frame starting a specified interval before the current row up to the current row. ```sql RANGE BETWEEN INTERVAL '7' DAY PRECEDING AND CURRENT ROW ``` -------------------------------- ### Get Topological Dimension of a Geometry Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/09-geospatial-functions/index.md Use ST_DIMENSION to find the topological dimension of a geometry. For example, a point has a dimension of 0. ```sql ST_DIMENSION(ST_MAKEGEOMPOINT(-122.35, 37.55)) ``` -------------------------------- ### Create Sample Users Table Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/01-table/70-flashback-table.md This snippet demonstrates how to create a sample 'users' table and insert initial data for testing flashback functionality. ```sql -- Create a sample users table CREATE TABLE users ( id INT, first_name VARCHAR, last_name VARCHAR, email VARCHAR, registration_date TIMESTAMP ); -- Insert sample data INSERT INTO users (id, first_name, last_name, email, registration_date) VALUES (1, 'John', 'Doe', 'john.doe@example.com', '2023-01-01 00:00:00'), (2, 'Jane', 'Doe', 'jane.doe@example.com', '2023-01-02 00:00:00'); ``` -------------------------------- ### Start Flink SQL Client Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/tutorials/migrate/migrating-from-mysql-with-flink-cdc.md Execute this command in your terminal to launch the Flink SQL Client. Ensure you are in the Flink installation directory. ```bash ./bin/sql-client.sh ``` -------------------------------- ### Start CPU Profiling with pprof Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/developer/20-community/00-contributor/04-how-to-profiling.md Use `go tool pprof` to start an HTTP server for CPU profiling. Access the profiling data via a web browser. ```bash go tool pprof -http="0.0.0.0:8081" http://localhost:8080/debug/pprof/profile?seconds=30 ``` -------------------------------- ### Launch BendSQL with UI Option Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/tutorials/getting-started/connect-to-databend-bendsql.md Starts BendSQL with a UI interface enabled, which opens a browser for interacting with Databend. Requires BendSQL to be installed. ```bash ❯ Bendsql -h 127.0.0.1 --port 8000 --ui ``` -------------------------------- ### Get Start of Year from Timestamp Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/to-start-of-year.md Use TO_START_OF_YEAR to find the first day of the year from a timestamp. The function accepts a date or timestamp expression. ```sql SELECT to_start_of_year('2023-11-12 09:38:18.165575'); ``` -------------------------------- ### Round Down to Start of Month Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/to-start-of-month.md Use TO_START_OF_MONTH to get the first day of the month from a given timestamp. Ensure the input is a valid date or timestamp. ```sql SELECT to_start_of_month('2023-11-12 09:38:18.165575'); ┌─────────────────────────────────────────────────┐ │ to_start_of_month('2023-11-12 09:38:18.165575') │ ├─────────────────────────────────────────────────┤ │ 2023-11-01 │ └─────────────────────────────────────────────────┘ ``` -------------------------------- ### Create and Insert Sample Data Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-any-value.md Sets up a sample 'sales' table with regional sales data for demonstrating aggregate functions. ```sql CREATE TABLE sales ( region VARCHAR, manager VARCHAR, sales_amount DECIMAL(10, 2) ); INSERT INTO sales VALUES ('North', 'Alice', 15000.00), ('North', 'Alice', 12000.00), ('South', 'Bob', 20000.00); ``` -------------------------------- ### Get Current Catalog Name Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/15-context-functions/current-catalog.md Use this function to retrieve the name of the active catalog for the current session. No specific setup or imports are required. ```sql SELECT CURRENT_CATALOG(); ``` ```sql ┌───────────────────┐ │ current_catalog() │ ├───────────────────┤ │ default │ └───────────────────┘ ``` -------------------------------- ### Create and Show Indexes Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/50-administration-cmds/show-indexes.md Demonstrates creating a table, an aggregating index on that table, and then displaying all created indexes. Use SHOW INDEXES to verify index creation. ```sql CREATE TABLE t1(a int,b int); CREATE AGGREGATING INDEX agg_idx AS SELECT avg(a), abs(sum(b)), abs(b) AS bs FROM t1 GROUP BY bs; SHOW INDEXES; ``` -------------------------------- ### Full Undrop Table Example Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/10-sql-commands/00-ddl/01-table/21-ddl-undrop-table.md This example shows the complete process: creating a table, dropping it, viewing it in history, and then undropping it. ```sql CREATE TABLE test(a INT, b VARCHAR); -- drop table DROP TABLE test; -- show dropped tables from current database SHOW TABLES HISTORY; -- restore table UNDROP TABLE test; ``` -------------------------------- ### Create Example Scores Table Source: https://github.com/databendlabs/databend-docs/blob/main/docs/cn/sql-reference/20-sql-functions/08-window-functions/ntile.md Sets up a sample table named 'scores' with student, subject, and score columns for demonstration purposes. ```sql CREATE TABLE scores ( student VARCHAR(20), subject VARCHAR(20), score INT ); INSERT INTO scores VALUES ('Alice', 'Math', 95), ('Alice', 'English', 87), ('Alice', 'Science', 92), ('Bob', 'Math', 85), ('Bob', 'English', 85), ('Bob', 'Science', 80), ('Charlie', 'Math', 88), ('Charlie', 'English', 85), ('Charlie', 'Science', 85); ``` -------------------------------- ### Self-hosted Databend Connection String Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/developer/00-drivers/index.md Example of a DSN for connecting to a self-hosted Databend instance. Ensure the port and sslmode are correctly specified for your setup. ```text databend://user:pwd@host:8000/database?sslmode=disable ``` -------------------------------- ### Full Partition Window Example Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/08-window-functions/rows-between.md Calculates the maximum and minimum amount within each product partition, considering all rows in the partition. ```sql SELECT sale_date, product, amount, MAX(amount) OVER ( PARTITION BY product ORDER BY sale_date ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS max_in_partition, MIN(amount) OVER ( PARTITION BY product ORDER BY sale_date ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS min_in_partition FROM sales ORDER BY product, sale_date; ``` -------------------------------- ### Truncate Date to Month and Week Source: https://github.com/databendlabs/databend-docs/blob/main/docs/en/sql-reference/20-sql-functions/05-datetime-functions/date-trunc.md Example of truncating a date to the beginning of the month and the beginning of the week. The week start is based on the default setting (Monday). ```sql SELECT DATE_TRUNC(MONTH, to_date('2022-07-07')), DATE_TRUNC(WEEK, to_date('2022-07-07')) ```