STARTSWITH

Return true when the input string begins with the given prefix, false otherwise.

Category: stringReturns: BOOLEANDialect: Standard

Syntax

STARTSWITH(str, prefix)

Description

## Overview Returns true when the input string begins with the given prefix, and false otherwise. STARTSWITH (no underscore) is the standard-dialect spelling; STARTS_WITH is a common SQL alias with identical semantics. The match is literal and case-sensitive. Prefix tests are the simplest way to partition data by a known-length leading code, dispatch rows into category buckets, and filter URLs, file paths, or namespaces. ## Behavior - Returns NULL when either argument is NULL. - Returns true for an empty prefix. - Returns false when the prefix is longer than the input string. - The match is case-sensitive and literal; SQL wildcards and regex metacharacters are not interpreted. - Operates on Unicode code points; multi-byte UTF-8 characters are matched correctly. - Short-circuits on the first mismatched character. ## Compatibility - STARTSWITH and STARTS_WITH are both supported and behave identically. - Equivalent to str LIKE prefix || '%' after wildcard escaping.

Parameters

NameTypeDescription
strSpecifies the input string to test.
prefixSpecifies the prefix to check for. The match is case-sensitive and literal.

Examples

-- Check URL protocol
SELECT STARTSWITH('https://example.com', 'https://');  -- true
-- Non-matching prefix
SELECT STARTSWITH('hello', 'world');  -- false
-- Case-sensitive
SELECT STARTSWITH('ABC', 'abc');  -- false
-- Empty prefix matches
SELECT STARTSWITH('anything', '');  -- true
-- NULL propagates
SELECT STARTSWITH(CAST(NULL AS VARCHAR), 'x');  -- NULL
-- Filter file paths by directory
SELECT file_path
FROM ops.etl.staging_files
WHERE STARTSWITH(file_path, '/var/log/');

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →