GalaxDB logo

CREATE TABLE

Creates a new table. Supports standard column definitions plus the EMBEDDING MODEL extension for automatic vector computation.

Syntax

SQL
CREATE TABLE [IF NOT EXISTS] table_name (
    column_name data_type [PRIMARY KEY] [NOT NULL]
        [EMBEDDING MODEL 'huggingface-model-id' DIM n],
    ...
);

Warning

PRIMARY KEY uniqueness is enforced - a duplicate key is rejected with SQLSTATE 23505, never a silent overwrite. NOT NULL, CHECK, UNIQUE (on non-primary-key columns), and FOREIGN KEY are parsed but not currently enforced at the storage layer. GalaxDB is not a drop-in PostgreSQL replacement - there are also no triggers, PL/pgSQL, views, sequences, or multi-column indexes yet.

Embedding Column

Add EMBEDDING MODEL 'model-id' DIM n to any TEXT column to enable automatic embedding computation. When you insert a row, the sidecar computes the embedding vector and stores it alongside the text value.

SQL
CREATE TABLE docs (
    id   INT PRIMARY KEY,
    body TEXT EMBEDDING MODEL 'sentence-transformers/all-MiniLM-L6-v2' DIM 384
);

The DIM value must match the model's output dimension:

  • sentence-transformers/all-MiniLM-L6-v2 → DIM 384 (default)
  • BAAI/bge-m3 → DIM 1024
  • Qwen/Qwen3-Embedding-0.6B → DIM 1024
  • Qwen/Qwen3-Embedding-4B → DIM 2560
  • Qwen/Qwen3-Embedding-8B → DIM 4096
  • google/embeddinggemma-300m → DIM 768
  • LiquidAI/LFM2.5-Embedding-350M → DIM 1024

Warning

The server must be started with --sidecar and --model flags to use embedding columns. Without the sidecar, INSERT into embedding columns returns a SidecarUnavailable error.

Data Types

TypeDescriptionExample
INT64-bit signed integer42, -100, 0
TEXTVariable-length UTF-8 string'hello world'
FLOAT64-bit floating point3.14, -0.5
BOOLBooleantrue, false
BLOBBinary datax'deadbeef'

Examples

Simple table

SQL
CREATE TABLE users (
    id    INT PRIMARY KEY,
    name  TEXT NOT NULL,
    email TEXT,
    age   INT
);

Table with embedding column

SQL
CREATE TABLE articles (
    id         INT PRIMARY KEY,
    title      TEXT NOT NULL,
    content    TEXT EMBEDDING MODEL 'sentence-transformers/all-MiniLM-L6-v2' DIM 384,
    created_at INT
);

Multiple embedding columns

SQL
CREATE TABLE products (
    id          INT PRIMARY KEY,
    name        TEXT NOT NULL,
    description TEXT EMBEDDING MODEL 'sentence-transformers/all-MiniLM-L6-v2' DIM 384,
    category    TEXT,
    price       FLOAT
);

IF NOT EXISTS

SQL
-- No error if table already exists
CREATE TABLE IF NOT EXISTS docs (
    id   INT PRIMARY KEY,
    body TEXT EMBEDDING MODEL 'sentence-transformers/all-MiniLM-L6-v2' DIM 384
);