Columns

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

Column

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(**attrs)

A table column definition

Column.to_map(no_privs)

Convert a column to a YAML-suitable format

Parameters:no_privs – exclude privilege information
Returns:dictionary
Column.add()

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

Returns:partial SQL statement
Column.add_privs()

Generate SQL statements to grant privileges on new column

Returns:list of SQL statements
Column.diff_privileges(incol)

Generate SQL statements to grant or revoke privileges

Parameters:incol – a YAML map defining the input column
Returns:list of SQL statements
Column.comment()

Return a SQL COMMENT statement for the column

Returns:SQL statement
Column.drop()

Return string to drop the column via ALTER TABLE

Returns:SQL statement
Column.rename(newname)

Return SQL statement to RENAME the column

Parameters:newname – the new name of the object
Returns:SQL statement
Column.set_sequence_default()

Return SQL statements to set a nextval() DEFAULT

Returns:list of SQL statements
Column.diff_map(incol)

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

Parameters:
  • table – table or type owning the columns/attributes
  • incols – YAML list defining the columns
ColumnDict.diff_map(incols)

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.

Table Of Contents

Previous topic

Tables, Views and Sequences

Next topic

Constraints

This Page