NAME
DBIO::DuckDB::DDL::Emit - Single source of DuckDB DDL statement shape
VERSION
version 0.900007
DESCRIPTION
The DuckDB DDL string templates -- column definitions, table/index/sequence statements, and the inline PK/UNIQUE/FK clauses -- live here so that the two producers of DDL agree on syntax char-for-char:
DBIO::DuckDB::DDL renders the desired schema from DBIO Result classes (
column_infohashrefs).DBIO::DuckDB::Diff::Table / DBIO::DuckDB::Diff::Column / DBIO::DuckDB::Diff::Index render CREATE / ALTER statements from an introspected model.
Each caller owns the field-extraction adapter for its own input shape (DBIO metadata vs introspected model) and feeds normalized pieces here. These functions are pure: identifiers are quoted by "quote_ident", nothing else is interpreted. Clauses are returned without indentation; "create_table" indents the body uniformly.
METHODS
quote_ident
my $sql = sprintf 'DROP TABLE %s;', quote_ident($table_name);
A name as DuckDB takes it for an identifier: between double quotes, every double quote inside it doubled. It is always quoted, whatever it looks like: a reserved word (order, group, end) has the same letters as item, and written bare it is a syntax error. DuckDB keeps the letter case of a quoted name and matches names case-insensitively either way, so quoting changes no object that is meant. This is the one quoter of the driver's DDL and diff statements.
split_table
my ($schema, $table) = split_table('other.t'); # ('other', 't')
my ($schema, $table) = split_table('t'); # (undef, 't')
A table name with one dot is a table of a schema: other.t is table t of schema other. Anything else is a plain name, a dot included.
quote_table
quote_table('other.t'); # "other"."t"
quote_table('t'); # "t"
A table name quoted for a statement, each part by "quote_ident".
column_def
column_def(name => $n, type => $t, not_null => $bool, default => $sql);
Renders "name" TYPE [NOT NULL] [DEFAULT $sql]. default is emitted verbatim -- the caller is responsible for quoting/escaping it (the two producers derive defaults very differently). Pass undef for no default.
pk_clause
pk_clause(@columns);
unique_clause
unique_clause(@columns);
fk_clause
fk_clause(from => \@local, to_table => $t, to => \@remote);
fk_clause(from => \@local, to_table => $t, to => \@remote,
on_delete => 'RESTRICT', on_update => 'NO ACTION');
on_delete and on_update are written as given, after the REFERENCES part; the caller has checked them, DuckDB takes RESTRICT and NO ACTION only.
create_table
create_table($table_name, @clause_strings);
Wraps the clauses (column defs, PK, UNIQUE, FK -- all unindented) in a CREATE TABLE statement, indenting each clause by two spaces.
create_index
create_index(name => $n, table => $t, columns => \@cols, unique => $bool);
create_index(name => $n, table => $t, expression => 'a, lower(b)');
An expression is written as the whole list between the parentheses and replaces columns.
create_sequence
create_sequence(name => $n);
create_sequence(name => $n, start => 1000000);
AUTHOR
DBIO Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.