Use this file to discover all available pages before exploring further.
DuckDB provides a comprehensive set of built-in functions for data manipulation, aggregation, and analysis. Functions are organized into categories based on their purpose and return type.
-- Count all rowsSELECT COUNT(*) FROM test;-- Count non-NULL valuesSELECT COUNT(i) FROM integers;-- Count distinct valuesSELECT COUNT(DISTINCT depname) FROM empsalary;
-- Concatenate stringsSELECT STRING_AGG(name, ', ') AS all_namesFROM employees;-- With orderingSELECT STRING_AGG(name, ', ' ORDER BY name) AS sorted_namesFROM employees;
-- Generate UUIDsSELECT UUID() AS unique_id;-- Hash functionsSELECT MD5(name) AS md5_hash, SHA256(name) AS sha256_hashFROM users;-- Type checkingSELECT TYPEOF(42) AS int_type, TYPEOF('hello') AS string_type;
Use DESCRIBE SELECT ... to see the schema and types of a query result, including function return types.
WITH processed_data AS ( SELECT empno, UPPER(TRIM(depname)) AS clean_dept, ROUND(salary * 1.1, 2) AS raised_salary, DATE_TRUNC('year', enroll_date) AS enroll_year, COALESCE(bonus, 0) AS bonus_amount FROM empsalary)SELECT clean_dept, COUNT(*) AS emp_count, AVG(raised_salary) AS avg_new_salary, SUM(bonus_amount) AS total_bonusesFROM processed_dataGROUP BY clean_dept, enroll_yearORDER BY clean_dept;
SELECT empno, -- Replace NULL with default COALESCE(bonus, 0) AS bonus, -- NULL if condition met NULLIF(salary, 0) AS safe_salary, -- Check for NULL CASE WHEN bonus IS NULL THEN 'No bonus' ELSE 'Has bonus' END AS bonus_statusFROM empsalary;