The column module defines two classes, Column derived from DbSchemaObject and ColumnDict, derived from DbObjectDict.


Column is derived from DbSchemaObject and represents a column in a table, or an attribute in a composite type. Its keylist attributes are the schema name and the table name.

A Column has the following attributes: name, type, not_null and default. The number attribute is also present but is not made visible externally.

class pyrseas.dbobject.column.Column(schema, name, description=None, owner=None, privileges=None, **attrs)

A table column definition


Convert a column to a YAML-suitable format

Parameters:no_privs – exclude privilege information

Return a string to specify the column in a CREATE or ALTER TABLE

Returns:partial SQL statement

Generate SQL statements to grant privileges on new column

Returns:list of SQL statements

Generate SQL statements to grant or revoke privileges

Parameters:incol – a YAML map defining the input column
Returns:list of SQL statements

Return a SQL COMMENT statement for the column

Returns:SQL statement

Return string to drop the column via ALTER TABLE

Returns:SQL statement

Return SQL statement to RENAME the column

Parameters:newname – the new name of the object
Returns:SQL statement

Return SQL statements to set a nextval() DEFAULT

Returns:list of SQL statements

Generate SQL to transform an existing column

Parameters:insequence – a YAML map defining the new column
Returns:list of partial SQL statements

Compares the column to an input column and generates partial SQL statements to transform it into the one represented by the input.

Column Dictionary

Class ColumnDict is a dictionary derived from DbObjectDict and represents the collection of columns in a database, across multiple tables. It is indexed by the schema name and table name, and each value is a list of Column objects.

class pyrseas.dbobject.column.ColumnDict(dbconn=None)

The collection of columns in tables in a database

ColumnDict.from_map(table, incols)

Initialize the dictionary of columns by converting the input list

  • table – table or type owning the columns/attributes
  • incols – YAML list defining the columns

Generate SQL to transform existing columns

Parameters:incols – a YAML map defining the new columns
Returns:list of SQL statements

Compares the existing column definitions, as fetched from the catalogs, to the input map and generates SQL statements to transform the columns accordingly.

This takes care of dropping columns that are not present in the input map. It’s separate so that it can be done last, after other table, constraint and index changes.