length()

Number of characters in string.

Arguments & returns

3 overloads

length(string)

Scalar
Overload link string Returns
#01 ANY[] BIGINT
#02 BIT BIGINT
#03 VARCHAR BIGINT

Example

2 more ↓
length example
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Engine example · Run to view results.

More examples

length example 2
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Engine example · Run to view results.

length example 3
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Engine example · Run to view results.

In other engines

Used in larger rewrites 3

These examples use length as one part of a larger SQL translation.

Apache Spark

ARRAY_INSERT(ARRAY(1, 2, 3), -2, 99)
In DuckDB
CASE WHEN [1, 2, 3] IS NULL THEN NULL ELSE LIST_CONCAT([1, 2, 3][1:LENGTH([1, 2, 3]) + -1], [99], [1, 2, 3][LENGTH([1, 2, 3]) + -1 + 1:]) END

SQLGlot example ↗

BigQuerylength()

SELECT LENGTH(foo)
In DuckDB
SELECT CASE TYPEOF(foo) WHEN 'BLOB' THEN OCTET_LENGTH(CAST(foo AS BLOB)) ELSE LENGTH(CAST(foo AS TEXT)) END

SQLGlot example ↗

Snowflakearray_remove_at()

ARRAY_REMOVE_AT([1, 2, 3], -1)
In DuckDB
CASE WHEN [1, 2, 3] IS NULL THEN NULL ELSE [1, 2, 3][1:LENGTH([1, 2, 3]) + -1] END

SQLGlot example ↗