1. MooseStack
  2. Data Types
  3. Nullable Types

On this page

Basic Optional FieldsOptional with ClickHouse DefaultsType Mapping ReferenceSee Also

Nullable Types

All types support nullable variants using optional syntax. Nullable columns can store NULL values.

Nullable performance impact

Nullable columns require a separate null bitmap that ClickHouse checks on every row access. This overhead applies even if only one row contains NULL. For frequently-queried columns, prefer using default values (e.g., 0, "", or a sentinel value) instead of Nullable.

Basic Optional Fields

interface User {  name: string;           // Required - NOT NULL  email?: string;         // Nullable(String)  age?: number;           // Nullable(Float64)  verified?: boolean;     // Nullable(Boolean)}

Optional with ClickHouse Defaults

If a field is optional but you provide a ClickHouse default, Moose creates a non-nullable column with a DEFAULT clause instead of a Nullable column.

import { ClickHouseDefault, WithDefault } from "@514labs/moose-lib"; interface User {  name: string;    // Optional without default → Nullable(Int64)  age?: number;    // Optional with default → Int64 DEFAULT 18 (non-nullable)  minAge?: number & ClickHouseDefault<"18">;    // Alternative helper syntax  status?: WithDefault<string, "'active'">;}

Type Mapping Reference

PatternTypeScriptPythonClickHouse Result
Requiredfield: Tfield: TT NOT NULL
Optionalfield?: TOptional[T] = NoneNullable(T)
Optional + Defaultfield?: T & ClickHouseDefault<"val">Annotated[Optional[T], clickhouse_default("val")]T DEFAULT val
Default value syntax

ClickHouse defaults are SQL expressions. String defaults must include quotes: "'active'" not "active". Numeric defaults are bare: "18" not "'18'".

See Also

  • ClickHouse Nullable — ClickHouse official documentation
  • Overview
  • Quick Start
  • Templates / Examples
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
MooseStack in your App
  • App / API frameworks
Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs
Deployment & Lifecycle
  • Moose Migrate
  • Moose Deploy
Reference
  • API Reference
  • Data Types
    • Strings
    • LowCardinality
    • Integers
    • Floats
    • Decimals
    • Booleans
    • Date & Time
    • Network
    • Arrays
    • Maps
    • Nested
    • Tuples
    • Enums
    • Geometry
    • JSON
    • Nullable
    • Aggregates
  • Table Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Changelog
Contribution
  • Documentation
  • Framework
FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplates
Changelog
Source506