Functions

The function module defines four classes: class Proc derived from DbSchemaObject, classes Function and Aggregate derived from Proc, and class ProcDict derived from DbObject.

Procedure

Class Proc is derived from DbSchemaObject and represents a regular or aggregate function.

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

A procedure such as a FUNCTION or an AGGREGATE

Proc.extern_key()

Return the key to be used in external maps for this function

Returns:string
Proc.identifier()

Return a full identifier for a function object

Returns:string

Function

Function is derived from Proc and represents a PostgreSQL user-defined function.

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

A procedural language function

Function.to_map(no_owner, no_privs)

Convert a function to a YAML-suitable format

Parameters:
  • no_owner – exclude function owner information
  • no_privs – exclude privilege information
Returns:

dictionary

Function.create(obj, *args, **kwargs)

Return SQL statements to CREATE or REPLACE the function

Parameters:newsrc – new source for a changed function
Returns:SQL statements
Function.diff_map(infunction)

Generate SQL to transform an existing function

Parameters:infunction – a YAML map defining the new function
Returns:list of SQL statements

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

Aggregate Function

Aggregate is derived from Proc and represents a PostgreSQL user-defined aggregate function.

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

An aggregate function

Aggregate.to_map(no_owner, no_privs)

Convert an agggregate to a YAML-suitable format

Parameters:
  • no_owner – exclude aggregate owner information
  • no_privs – exclude privilege information
Returns:

dictionary

Aggregate.create(obj, *args, **kwargs)

Return SQL statements to CREATE the aggregate

Returns:SQL statements

Procedure Dictionary

ProcDict is derived from DbObjectDict. It is a dictionary that represents the collection of regular and aggregate functions in a database.

class pyrseas.dbobject.function.ProcDict(dbconn=None)

The collection of regular and aggregate functions in a database

ProcDict.from_map(schema, infuncs)

Initalize the dictionary of functions by converting the input map

Parameters:
  • schema – schema owning the functions
  • infuncs – YAML map defining the functions
ProcDict.diff_map(infuncs)

Generate SQL to transform existing functions

Parameters:infuncs – a YAML map defining the new functions
Returns:list of SQL statements

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