Why NQL needs its own type system
Different database engines handle types differently:- Snowflake uses
NUMBER,VARCHAR,VARIANTfor semi-structured data - Spark uses
LONG,STRING, and nested types with specific semantics - BigQuery uses
INT64,STRING, andSTRUCT/ARRAYwith its own rules
Primitive types
NQL’s primitive types map to standard database types across all supported engines:| NQL Type | Snowflake | Spark | Description |
|---|---|---|---|
STRING / VARCHAR | VARCHAR | STRING | Variable-length text |
BOOLEAN | BOOLEAN | BOOLEAN | True/false |
LONG / BIGINT | NUMBER | BIGINT | 64-bit integer |
DOUBLE | FLOAT | DOUBLE | 64-bit floating point |
DECIMAL | NUMBER | DECIMAL | Arbitrary precision |
DATE | DATE | DATE | Calendar date |
TIMESTAMP | TIMESTAMP_NTZ | TIMESTAMP | Date and time |
When precision matters
For financial or measurement data where exact precision is required, useDECIMAL instead of DOUBLE:
Complex types
Data collaboration often involves hierarchical and nested data structures. NQL supports three complex types that work consistently across engines.Arrays
Arrays store ordered collections of same-type elements. They’re useful for:- Lists of identifiers
- Tags or categories
- Time-series values
Structs
Structs group named fields with potentially different types—like a row within a row. They’re useful for:- Nested attributes
- Composite identifiers
- Grouped metadata
Maps
Maps store key-value pairs where all keys share a type and all values share a type. They’re useful for:- Dynamic properties
- Metadata with variable keys
- Key-value attributes
Nested types
Complex types can be nested to represent hierarchical data:Accessing nested data
Use dot notation for struct fields and bracket notation for arrays:Type coercion
NQL automatically converts types in certain contexts to reduce the need for explicit casting.Implicit coercion
| Context | Behavior |
|---|---|
| Numeric comparisons | Smaller types promoted to larger (LONG → DOUBLE) |
| String concatenation | Non-strings converted to strings |
| Boolean context | Some conversions allowed |
When to use explicit CAST
UseCAST when:
- Converting between incompatible types
- Ensuring specific precision
- Documenting intent clearly
NULL handling
NULL represents missing or unknown data. Understanding NULL behavior prevents subtle bugs.NULL in comparisons
NULL is not equal to anything, including itself:IS NULL and IS NOT NULL for NULL checks:
NULL in operations
Operations involving NULL typically return NULL:NULL-safe comparisons
UseIS NOT DISTINCT FROM for NULL-safe equality:

