Primitive types

Primitive types store basic values such as numbers, text, booleans, and dates.

Table of Content


Null Values

Definition: NULL represents a missing or unknown value.

Notes:

  • Not the same as 0, '' (empty string), {} (empty object), [] (empty array), or any zero-equivalent.

  • Columns omitted during INSERT get NULL values.

  • Outer joins produce NULL for unmatched rows.

  • Use NOT NULL to prevent NULL values.

Examples:

Preventing NULL values:


Boolean

Definition: Stores a logical value: TRUE or FALSE.

Example:


VARCHAR(n)

Definition: Variable-length strings, maximum n characters (1 ≤ n ≤ 2^31 - 1).

Behavior:

  • Exceeding n causes an error (unless cast).

  • Trailing spaces are truncated.

  • Casting truncates without error.

Example:


CHARACTER(n)

Definition: Fixed-length strings, blank-padded to n characters.

Behavior:

  • Over-length values cause an error (unless cast).

  • Shorter values are right-padded with spaces.

  • Casting truncates without error.

Example:


TEXT

Definition: Unbounded variable-length Unicode text.

Notes:

  • Max indexed length: 32,766 bytes (UTF-8) for column store.

  • Use OBJECT for structured JSON-like data.

Example:


json

Definition: PostgreSQL-compatible JSON type (only for casting, not table columns).

Examples:


Numeric types

CrateDB supports:

  • SMALLINT

  • INTEGER

  • BIGINT

  • NUMERIC(precision, scale)

  • REAL

  • DOUBLE PRECISION

Notes:

  • REAL and DOUBLE PRECISION are inexact (floating-point).

  • Aggregates (SUM, AVG) on floats may vary slightly due to rounding.

  • Supports IEEE 754 special values: NaN, Infinity, -Infinity, -0.

Example:

Inserting special values:

Last updated