CREATE TABLE
Create a new table.
Syntax
Column definition
Table constraints
Parameters
| Parameter | Description |
|---|---|
IF NOT EXISTS | Do not return an error if a table with the same name already exists |
| table_name | The name of the table to create |
| column_name | The name of a column |
| data_type | The data type of the column |
PRIMARY KEY | Mark the column as the primary key |
NOT NULL | The column cannot contain null values |
DEFAULT expression | Default value for the column |
CHECK (expression) | Check constraint — validates that the expression is true for every row |
REFERENCES table(column) | Foreign key constraint |
USING EXTERNAL | Create a table backed by an external file |
| file_path | Path to the external file (e.g., Parquet) |
Examples
Basic table
CREATE TABLE articles (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
body TEXT,
views INTEGER DEFAULT 0
);
Table with foreign keys
CREATE TABLE comments (
id INTEGER PRIMARY KEY,
article_id INTEGER REFERENCES articles(id),
author TEXT NOT NULL,
body TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
External table (Parquet)
CREATE TABLE movies_external (
title TEXT,
year INTEGER,
rating FLOAT
) USING EXTERNAL WITH (
PATH = '/data/movies.parquet'
);
External table on S3
CREATE TABLE movies_s3 (
title TEXT,
year INTEGER,
rating FLOAT
) USING EXTERNAL WITH (
PATH = 's3://my-bucket/data/movies.parquet',
FORMAT = 'Parquet',
S3_ACCESS_KEY = 'your-access-key',
S3_SECRET_KEY = 'your-secret-key',
S3_REGION = 'us-east-1'
);
External table options
External tables support the same storage and format options as COPY. Use WITH (HELP) to see all available options:
CREATE TABLE t (id INT) USING EXTERNAL WITH (HELP);
| Option | Default | Description |
|---|---|---|
PATH | (required) | Path to the external file (local or s3://) |
FORMAT | Text | File format: Text, Csv, Parquet, Dwrf, Orc |
DELIMITER | , (CSV) or \t (Text) | Column delimiter |
HEADER | FALSE | First line is a header row |
See COPY — S3 options for S3 authentication and connection parameters.