Function Categories
Materialize’s SQL functions are organized into the following categories:Aggregate Functions
Aggregate functions perform calculations across multiple rows and return a single result. Common aggregate functions include:- COUNT: Count the number of rows
- SUM: Calculate the sum of numeric values
- AVG: Calculate the average of numeric values
- MIN/MAX: Find minimum or maximum values
- STDDEV/VARIANCE: Calculate statistical measures
- array_agg: Aggregate values into an array
- string_agg: Concatenate strings with a delimiter
- jsonb_agg: Aggregate values as a JSONB array
String Functions
String functions manipulate and analyze text data:- CONCAT: Concatenate strings
- SUBSTRING: Extract substrings
- UPPER/LOWER: Convert case
- LENGTH: Get string length
- REGEXP: Pattern matching with regular expressions
- normalize: Unicode normalization
Date and Time Functions
Date and time functions work with temporal data types:- NOW(): Current timestamp
- mz_now(): Logical timestamp
- DATE_TRUNC: Truncate to time component
- EXTRACT: Extract time components
- datediff: Calculate date differences
- date_bin: Align timestamps to intervals
JSON Functions
JSON functions process JSONB data:- Operators:
->,->>,@>,?for accessing and querying JSON - jsonb_agg: Aggregate as JSONB array
- jsonb_object_agg: Aggregate as JSONB object
- jsonb_build_array/object: Construct JSON values
- to_jsonb: Convert values to JSONB
Operators
Materialize supports standard SQL operators:Comparison Operators
=,<>,!=: Equality and inequality<,>,<=,>=: ComparisonBETWEEN,IN: Range and set membershipIS NULL,IS NOT NULL: Null checkingLIKE,ILIKE: Pattern matching
Arithmetic Operators
+,-,*,/: Basic arithmetic%: Modulo&,|,#,~: Bitwise operations<<,>>: Bit shifting
Logical Operators
AND,OR,NOT: Boolean logicIS TRUE,IS FALSE,IS UNKNOWN: Boolean testing
String Operators
||: Concatenation~,~*,!~,!~*: Regular expression matching
Unmaterializable Functions
Some functions are unmaterializable because their output depends on external state (like session parameters or transaction timestamps). These functions:- Cannot be used in indexes or materialized views
- Can be used in non-materialized views and
SELECTstatements - Include functions like
now(), session variables, etc.
Type Casting
Convert values between types using theCAST function or :: operator:
- Implicit: Automatic conversions
- Assignment: Conversions when inserting data
- Explicit: Require explicit
CASTor::