Data Types
This page is a practical guide for using data types in SQL when building with KalamDB.
Data types are independent from table types, but some types have table-type-specific behavior. FILE
columns are supported on USER and SHARED tables, and EMBEDDING(n) columns become most useful
with vector search. See /docs/server/architecture/table-types
for the table boundary.
Type Selection Flow
Quick Type Selection
Use this table when deciding a column type:
| You store… | Use | Why |
|---|---|---|
IDs from SNOWFLAKE_ID() | BIGINT | 64-bit integer ID generation |
| Small whole numbers (status, counters) | INT | Compact and fast |
| Large counters | BIGINT | Higher range |
| User-facing text | TEXT | Flexible string storage |
| True/false values | BOOLEAN | Clear semantics |
| Decimal money-like values | DECIMAL(p,s) | Exact precision |
| Timestamps | TIMESTAMP | Time-based queries and ordering |
| Dates only | DATE | Calendar values without time |
| Structured document payload | JSON | Nested object/array data |
| Vector embeddings | EMBEDDING(n) | Semantic retrieval and similarity search |
Common Types in Practice
Integer Types
- Prefer
INTfor bounded counts. - Prefer
BIGINTfor IDs and values that can grow large.
Text and Boolean
- Use
TEXTfor variable-length strings. - Use
BOOLEANinstead of0/1integers for feature flags and state.
Decimal Values
- Use
DECIMALfor exact arithmetic (pricing, balances, rates). - Pick precision/scale deliberately, e.g.
DECIMAL(12,2).
Time Types
- Use
TIMESTAMPfor event records and ordering. - Use
DATEwhen time-of-day is not needed.
JSON Payloads
- Use
JSONfor dynamic payloads and schema-flexible metadata. - Keep frequently filtered fields as typed top-level columns.
Embeddings for Vector Search
- Use
EMBEDDING(n)for fixed-size vector columns. - Pick
nto match the embedding model you generate in your app or worker. - Index the embedding column before using it for nearest-neighbor retrieval.
Type Conversion
Use explicit casts when moving between compatible types.
Prefer explicit conversion over relying on implicit casting in critical queries.
Nullability and Defaults
Use NOT NULL for required fields and DEFAULT for stable inserts.
Recommended Patterns
- IDs:
BIGINT PRIMARY KEY DEFAULT SNOWFLAKE_ID() - Created timestamps:
TIMESTAMP NOT NULL DEFAULT NOW() - Money/rates:
DECIMAL(not floating point) - Optional user text: nullable
TEXT - Real-time transient events:
STREAM+TTL_SECONDS
Related Docs
Last updated on