NAME

DBIO::Informix::ColumnDef - Render a single Informix column definition fragment

VERSION

version 0.900007

DESCRIPTION

DBIO::Informix::ColumnDef owns the grammar of a single Informix column definition -- the name type [DEFAULT ...] [NOT NULL] fragment shared by CREATE TABLE, ALTER TABLE ADD (...) and ALTER TABLE MODIFY.

Before this module the same fragment was assembled independently in DBIO::Informix::DDL, DBIO::Informix::Diff::Table and DBIO::Informix::Diff::Column, each with its own subtle drift (default quoting, SERIAL placement). Those three call sites now delegate here so the dialect lives in one place.

Type normalization stays with the caller: the diff path already carries a full SQL type string (varchar(255)), whereas the DDL path resolves a logical type via _informix_column_type. This module only assembles the fragment from an already-resolved type.

use DBIO::Informix::ColumnDef qw(column_def_sql);

my $sql = column_def_sql(
    name              => 'name',
    type              => 'varchar(255)',
    not_null          => 1,
    default_value     => \'today',     # SCALAR ref => literal SQL
    is_auto_increment => 0,
);
# => name varchar(255) DEFAULT today NOT NULL

METHODS

column_def_sql

my $fragment = column_def_sql(%spec);

Returns the column-definition fragment (no leading indent, no trailing comma). %spec keys:

  • name -- column name, quoted as an identifier.

  • type -- already-resolved SQL type string. Ignored when is_auto_increment is set (Informix SERIAL is itself a type).

  • not_null -- truthy emits NOT NULL, after any DEFAULT: Informix takes the DEFAULT clause before the column constraint (HCL OneDB/Informix SQL Syntax, ALTER TABLE ADD/MODIFY, ids_sqs_0077 / ids_sqs_0078, example DEFAULT 1 NOT NULL; live unmeasured).

  • default_value -- a SCALAR ref is emitted as literal SQL (the ANSI CURRENT_TIMESTAMP, NOW(), CURRENT_DATE and CURRENT_USER become CURRENT YEAR TO FRACTION(5), TODAY and USER); a plain scalar is quoted (a ' doubled) only for character types; undef emits no default. A SERIAL column never emits a default.

  • size -- the size of the introspected model (a number, or [precision, scale]), added to a type that does not carry one itself (see "ddl_type" in DBIO::Informix::Types).

  • is_auto_increment -- truthy makes the type SERIAL, or stays SERIAL8 / BIGSERIAL when type is one of them.

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.