NAME

DBIO::DB2::Introspect::Columns - Introspect DB2 columns

VERSION

version 0.900007

DESCRIPTION

Fetches column metadata via SYSCAT.COLUMNS. Primary-key membership is determined via SYSCAT.KEYCOLUSE joined with SYSCAT.TABCONST.

METHODS

fetch

my $columns = DBIO::DB2::Introspect::Columns->fetch($dbh, $schema, $tables);

Given the tables hashref from DBIO::DB2::Introspect::Tables, returns a hashref keyed by table name. Each value is an arrayref of column hashrefs in COLNO order.

The normalized fields are the DBIO::Introspect::Base contract that DBIO::Generate reads through table_columns_info (ADR 0013): column_name, data_type, size, not_null, default_value, is_pk, pk_position, and is_auto_increment (set to 1 only for GENERATED ... AS IDENTITY columns).

  • data_type is the lower-case type name a result class writes: char for CHARACTER, double precision for DOUBLE, otherwise TYPENAME lower-cased (varchar, integer, decfloat, timestamp).

  • size is the declared length: a number for CHAR, VARCHAR, BINARY, VARBINARY, GRAPHIC, VARGRAPHIC, CLOB, BLOB, DBCLOB; [precision, scale] for DECIMAL; the fractional-seconds precision for TIMESTAMP; the digits (16 or 34) for DECFLOAT. Absent for a type Db2 declares without one (SMALLINT, INTEGER, BIGINT, REAL, DOUBLE, DATE, TIME, XML, BOOLEAN, LONG VARCHAR), whose LENGTH in the catalog is its storage length.

  • default_value is the value: a string without its quotes ('it''s' is it's), a number as its text, and an expression (CURRENT TIMESTAMP, USER, CURRENT DATE, ...) as a SCALAR reference (\'CURRENT TIMESTAMP'), the form DBIO::DB2::DDL writes bare. No default, and an explicit DEFAULT NULL, are undef.

The catalog fields are internal, for DBIO::DB2::Diff and its operations, which render and compare what the catalog holds. They are not part of any contract and no other consumer reads them:

  • catalog_type is TYPENAME (CHARACTER, DOUBLE).

  • catalog_size is LENGTH -- the storage length for a type declared without one -- with SCALE after a comma when that is above zero (10,2). TIMESTAMP is the exception, its value is SCALE alone; DECFLOAT carries its digits, LENGTH 8 or 16 as 16 or 34.

  • catalog_default is DEFAULT, the SQL text of the default ('new' with its quotes, 'it''s', 0, CURRENT TIMESTAMP). One exception, for a BOOLEAN: a quoted number ('1') is read as the number (1), the form DBIO::DB2::DDL writes for a class value of digits, so the column made by hand with DEFAULT '1' and the one made from its class do not differ; TRUE, FALSE and a quoted word ('true') stay.

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.