Skip to main content

Data Types

ScramDB supports the most common PostgreSQL data types. The table below shows the mapping between PostgreSQL types and their ScramDB equivalents.

PostgreSQL → ScramDB Type Mapping

PostgreSQL TypeScramDB TypeSizeStatusNotes
SMALLINT / INT2Int162 bytesStored natively as 16-bit
INTEGER / INT4Int324 bytes
BIGINT / INT8Int648 bytes
REAL / FLOAT4Float324 bytesIEEE 754 single precision
DOUBLE PRECISION / FLOAT8Float648 bytesIEEE 754 double precision
BOOLEANBoolean1 bitValidity bitmask
VARCHAR(n) / TEXTUtf8VariableVariable-length UTF-8
CHAR(n)Utf8VariableFixed-width, space-padded
DATEDate324 bytesDays since epoch
TIMESTAMPTimestampMicro8 bytesMicrosecond precision
DECIMAL(p,s) / NUMERICDecimal12816 bytes128-bit decimal with precision/scale
INTERVALIntervalMDN16 bytesMonth-Day-Nano representation
VECTOR(n)Vectorn × 4 bytespgvector-compatible, float32 elements
UUID--⚠️ Plannedv28
JSONB--⚠️ Plannedv28
ARRAY types--⚠️ Plannedv28
BYTEA--⚠️ Planned
SERIAL / BIGSERIAL--⚠️ Plannedv27 (auto-increment)

Type Behavior

Numeric Types

  • Integer arithmetic follows standard SQL semantics (exact)
  • Floating-point arithmetic uses IEEE 754
  • Integer overflow is checked at runtime
  • Implicit casting follows PostgreSQL promotion rules: INT2 → INT4 → INT8 → FLOAT4 → FLOAT8

String Types

  • All strings are stored as UTF-8
  • VARCHAR(n) enforces max length at insertion
  • TEXT and VARCHAR (without length) are equivalent
  • String comparison is byte-wise (no collation support yet)
  • Short strings (≤8 bytes) are optimized for JIT - packed into 64-bit registers

Date/Time Types

  • DATE is stored as days since Unix epoch (1970-01-01)
  • TIMESTAMP is stored as microseconds since epoch
  • EXTRACT() supports: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, EPOCH, DOW, DOY, QUARTER, WEEK
  • Date arithmetic is implemented via Howard Hinnant's civil date algorithm

NULL Handling

  • All types are nullable
  • NULL semantics follow SQL standard (three-valued logic)
  • IS NULL / IS NOT NULL for NULL checks
  • COALESCE() and NULLIF() are supported
  • Validity tracked via per-column bitmask (1 bit per row)

Type Casting

Explicit casts use the CAST function or :: syntax:

SELECT CAST(price AS INTEGER) FROM products;
SELECT price::INTEGER FROM products;

Supported Casts

FromToMethod
Any integerAny integerTruncation/extension
IntegerFloatExact conversion
FloatIntegerTruncation
StringInteger/FloatParse
Integer/FloatStringFormat
StringDate/TimestampParse (ISO 8601)
DateTimestampMidnight
TimestampDateTruncate time