FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplatesGuides
Release Notes
Source514
  1. MooseStack
  2. Data Types
  3. Nullable Types

On this page

Basic Optional FieldsOptional with ClickHouse DefaultsType Mapping ReferenceSee Also
  • Overview
Build a New App
  • 5 Minute Quickstart
  • Browse Templates
  • Existing ClickHouse
Add to Existing App
  • Next.js
  • Fastify
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
Moose Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs & Web Apps
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
  • Release Notes
Contribution
  • Documentation
  • Framework

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
interface User {  name: string;           // Required - NOT NULL  email?: string;         // Nullable(String)  age?: number;           // Nullable(Float64)  verified?: boolean;     // Nullable(Boolean)}
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'">;}