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 Type | ScramDB Type | Size | Status | Notes |
|---|---|---|---|---|
SMALLINT / INT2 | Int16 | 2 bytes | ✅ | Stored natively as 16-bit |
INTEGER / INT4 | Int32 | 4 bytes | ✅ | |
BIGINT / INT8 | Int64 | 8 bytes | ✅ | |
REAL / FLOAT4 | Float32 | 4 bytes | ✅ | IEEE 754 single precision |
DOUBLE PRECISION / FLOAT8 | Float64 | 8 bytes | ✅ | IEEE 754 double precision |
BOOLEAN | Boolean | 1 bit | ✅ | Validity bitmask |
VARCHAR(n) / TEXT | Utf8 | Variable | ✅ | Variable-length UTF-8 |
CHAR(n) | Utf8 | Variable | ✅ | Fixed-width, space-padded |
DATE | Date32 | 4 bytes | ✅ | Days since epoch |
TIMESTAMP | TimestampMicro | 8 bytes | ✅ | Microsecond precision |
DECIMAL(p,s) / NUMERIC | Decimal128 | 16 bytes | ✅ | 128-bit decimal with precision/scale |
INTERVAL | IntervalMDN | 16 bytes | ✅ | Month-Day-Nano representation |
VECTOR(n) | Vector | n × 4 bytes | ✅ | pgvector-compatible, float32 elements |
UUID | - | - | ⚠️ Planned | v28 |
JSONB | - | - | ⚠️ Planned | v28 |
ARRAY types | - | - | ⚠️ Planned | v28 |
BYTEA | - | - | ⚠️ Planned | |
SERIAL / BIGSERIAL | - | - | ⚠️ Planned | v27 (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 insertionTEXTandVARCHAR(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
DATEis stored as days since Unix epoch (1970-01-01)TIMESTAMPis stored as microseconds since epochEXTRACT()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 NULLfor NULL checksCOALESCE()andNULLIF()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
| From | To | Method |
|---|---|---|
| Any integer | Any integer | Truncation/extension |
| Integer | Float | Exact conversion |
| Float | Integer | Truncation |
| String | Integer/Float | Parse |
| Integer/Float | String | Format |
| String | Date/Timestamp | Parse (ISO 8601) |
| Date | Timestamp | Midnight |
| Timestamp | Date | Truncate time |