Skip to main content
NQL supports primitive types for scalar values and complex types for structured data. This reference covers all supported types and type conversion.

Primitive types

TypeAliasesDescriptionExample literals
STRINGVARCHARVariable-length text'hello world'
BOOLEANTrue or falsetrue, false
LONGBIGINT64-bit signed integer12345678901234
DOUBLE64-bit floating point3.14159
DECIMALArbitrary precision numberCAST(10.12345 AS DECIMAL)
DATEDate without time'2024-01-15'
TIMESTAMPDate with time'2024-01-15 10:30:00'

STRING / VARCHAR

Variable-length character data. String literals use single quotes.
SELECT
  'Hello, World!' AS greeting,
  CONCAT(first_name, ' ', last_name) AS full_name
FROM company_data."123"

Escape sequences

SequenceMeaning
''Single quote
\\Backslash
SELECT 'It''s a test' AS escaped_quote

BOOLEAN

Logical true/false values.
SELECT
  is_active,
  CASE WHEN score > 90 THEN true ELSE false END AS is_high_performer
FROM company_data."123"
WHERE is_verified = true

LONG / BIGINT

64-bit signed integers. Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
SELECT
  user_id,
  CAST(timestamp_value AS LONG) AS epoch_millis
FROM company_data."123"

DOUBLE

64-bit IEEE 754 floating-point numbers. Use for approximate numeric calculations.
SELECT
  amount * 1.0825 AS amount_with_tax,
  SQRT(value) AS square_root
FROM company_data."123"
Floating-point arithmetic can produce rounding errors. Use DECIMAL for financial calculations requiring exact precision.

DECIMAL

Arbitrary-precision decimal numbers. Use for exact calculations where precision matters.
SELECT
  CAST(price AS DECIMAL) AS exact_price,
  CAST(quantity AS DECIMAL) * CAST(unit_price AS DECIMAL) AS line_total
FROM company_data."123"

DATE

Calendar date without time component. Format: YYYY-MM-DD.
SELECT
  event_date,
  DATE_TRUNC('month', event_date) AS month_start
FROM company_data."123"
WHERE event_date >= '2024-01-01'

Date arithmetic

SELECT
  event_date,
  DATE_ADD(event_date, 30) AS plus_30_days,
  event_date - INTERVAL '7' DAY AS minus_7_days
FROM company_data."123"

TIMESTAMP

Date and time with precision. Format: YYYY-MM-DD HH:MM:SS.
SELECT
  event_timestamp,
  DATE_TRUNC('hour', event_timestamp) AS hour_start
FROM company_data."123"
WHERE event_timestamp > CURRENT_TIMESTAMP - INTERVAL '24' HOUR

Current timestamp functions

FunctionReturns
CURRENT_DATECurrent date
CURRENT_TIMESTAMPCurrent timestamp

Complex types

NQL supports three complex types for structured data: arrays, structs, and maps.

ARRAY

Ordered collection of elements of the same type.

Array literal

SELECT ARRAY('value1', 'value2', 'value3') AS my_array

Array type declaration

CAST(column AS ARRAY<STRING>)
CAST(column AS ARRAY<LONG>)
CAST(column AS ARRAY<STRUCT<name:STRING, age:LONG>>)

Accessing array elements

Use zero-based indexing with bracket notation:
SELECT
  identifiers[0] AS first_id,
  identifiers[1] AS second_id,
  identifiers[0].type AS first_id_type
FROM company_data."123"

Array functions

FunctionDescription
SIZE(array)Returns number of elements
ELEMENT_AT(array, index)Returns element at index
ARRAY_FLATTEN(array)Flattens nested arrays
See Functions Reference for complete array function documentation.

STRUCT

Named collection of fields with potentially different types. Similar to a row or record.

Struct literal

SELECT NAMED_STRUCT(
  'name', 'John Doe',
  'age', 30,
  'active', true
) AS person

Struct type declaration

CAST(column AS STRUCT<name:STRING, age:LONG>)
CAST(column AS STRUCT<
  user:STRUCT<id:LONG, email:STRING>,
  created_at:TIMESTAMP
>)

Accessing struct fields

Use dot notation to access fields:
SELECT
  person.name,
  person.age,
  address.city
FROM company_data."123"

Nested struct access

SELECT
  company_data."1".nested_field.deep_field.value
FROM company_data."1"

MAP

Collection of key-value pairs. Keys must be of a single type, as must values.

Map type declaration

CAST(column AS MAP<STRING, STRING>)
CAST(column AS MAP<STRING, LONG>)
CAST(column AS MAP<STRING, STRUCT<a:STRING, b:LONG>>)

Accessing map values

Use ELEMENT_AT to retrieve values by key:
SELECT
  ELEMENT_AT(properties, 'color') AS color,
  ELEMENT_AT(metadata, 'source') AS source
FROM company_data."123"

Nested types

Complex types can be nested to represent hierarchical data structures.

Array of structs

CAST(column AS ARRAY<STRUCT<
  type:STRING,
  value:STRING,
  timestamp:LONG
>>)
Access nested struct fields within arrays:
SELECT
  identifiers[0].type AS first_type,
  identifiers[0].value AS first_value
FROM company_data."123"

Map with struct values

CAST(column AS MAP<STRING, STRUCT<
  count:LONG,
  last_seen:TIMESTAMP
>>)

Deeply nested structures

CAST(column AS STRUCT<
  field1:STRING,
  field2:MAP<STRING, STRUCT<a:LONG>>,
  field3:ARRAY<MAP<STRING, STRING>>
>)

Type casting

Use CAST to convert between types.

Syntax

CAST(expression AS target_type)

Common conversions

SELECT
  CAST(numeric_string AS LONG) AS number,
  CAST(amount AS VARCHAR) AS amount_text,
  CAST(timestamp_value AS DATE) AS date_only,
  CAST(epoch_millis AS TIMESTAMP) AS datetime,
  CAST(value AS DECIMAL) AS precise_value
FROM company_data."123"

Casting complex types

SELECT
  CAST(raw_array AS ARRAY<STRING>) AS string_array,
  CAST(raw_struct AS STRUCT<id:LONG, name:STRING>) AS typed_struct,
  CAST(NULL AS MAP<STRING, LONG>) AS empty_map
FROM company_data."123"
When casting to complex types, the source data must have a compatible structure. Invalid casts return NULL or raise an error.

Type coercion

NQL automatically converts types in some contexts:
ContextBehavior
ComparisonNumeric types promoted to common type
ArithmeticInteger operations with DOUBLE operand return DOUBLE
ConcatenationNon-strings converted to STRING with || operator
AggregationResults match input type or use promoted type

Explicit vs implicit conversion

Prefer explicit CAST for clarity:
-- Explicit (preferred)
WHERE CAST(string_column AS LONG) > 100

-- Implicit (may work but less clear)
WHERE string_column > '100'

NULL values

NULL represents missing or unknown data. NULL behaves specially in comparisons and operations.

NULL checks

WHERE email IS NOT NULL
WHERE phone IS NULL

NULL in expressions

Any operation involving NULL typically returns NULL:
SELECT
  NULL + 1,           -- Returns NULL
  CONCAT('Hi ', NULL) -- Returns NULL

COALESCE

Return the first non-NULL value:
SELECT COALESCE(preferred_email, backup_email, 'unknown') AS email
FROM company_data."123"

NULLIF

Return NULL if two values are equal:
SELECT NULLIF(status, 'unknown') AS clean_status
FROM company_data."123"