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:
Type inference
NQL infers types from context when possible:ARRAY type inference
Array literals infer element type from contents:Cross-engine considerations
While NQL abstracts type differences, some edge cases exist:Timestamp precision
Different engines support different timestamp precision. NQL uses millisecond precision as the common denominator.String collation
String comparison and sorting may differ slightly between engines. For consistent behavior, normalize strings (lowercase, trim) before comparison.Numeric overflow
Large numbers may overflow differently across engines. For critical calculations, consider using DECIMAL with explicit precision.Troubleshooting type errors
UnsupportedTypeError
This error occurs when an operation doesn’t support the given types:Type mismatch in arrays
All array elements must have the same type:NULL type resolution
NULL by itself has no type. In some contexts, you need to cast NULL:Related content
Data Types Reference
Complete type reference with syntax
NQL vs SQL
How NQL types compare to standard SQL
Functions Reference
Type conversion and manipulation functions
Troubleshooting
Common type-related errors and solutions

