← Back to Glossary

DEFAULT value

A DEFAULT value is a value a database column automatically takes on when an INSERT statement doesn't explicitly specify a value for it.

Overview

Declaring a DEFAULT for a column saves every INSERT statement from having to specify a value explicitly, and centralizes a column's fallback behavior in one place in the schema instead of scattering it across application code. Defaults are only applied when a value is omitted (or, in most databases, when DEFAULT is used explicitly in the VALUES list) — they don't override an explicitly provided value, including an explicit NULL.

Syntax

Copy code

CREATE TABLE events ( id INTEGER, status VARCHAR DEFAULT 'pending', created_at TIMESTAMP DEFAULT current_timestamp ); INSERT INTO events (id) VALUES (1); -- status becomes 'pending', created_at becomes the current time

Defaults with Expressions and Sequences

Defaults aren't limited to constants — they can be any expression, including a call to generate a surrogate key from a sequence:

Copy code

CREATE SEQUENCE event_seq START 1; CREATE TABLE events ( id INTEGER DEFAULT nextval('event_seq'), status VARCHAR DEFAULT 'pending' );

DuckDB Support

DuckDB supports DEFAULT values with constant literals, expressions, and sequence calls via nextval(), matching the syntax above. This makes DEFAULT nextval('seq_name') DuckDB's standard pattern for auto-incrementing surrogate keys, since DuckDB doesn't have a dedicated SERIAL or AUTO_INCREMENT type.

Related terms

FAQS

No. A DEFAULT only applies when a column's value is omitted from the INSERT; an explicitly provided value, including an explicit NULL, is used instead.

Create a SEQUENCE and set the column's DEFAULT to nextval('sequence_name'), since DuckDB doesn't have a SERIAL type.