pglast.printers — Specialized printer functions

This module implements the specialized functions that for any given tag define how the associated Node will be serialized.

pglast.printers.NODE_PRINTERS = {'AccessPriv': <function access_priv>, 'AlterCollationStmt': <function alter_collation_stmt>, 'AlterDatabaseStmt': <function alter_database_stmt>, 'AlterDatabaseSetStmt': <function alter_database_set_stmt>, 'AlterExtensionStmt': <function alter_extension_stmt>, ('AlterExtensionStmt', 'DefElem'): <function alter_extension_stmt_def_elem>, 'AlterExtensionContentsStmt': <function alter_extension_contents_stmt>, 'AlterEnumStmt': <function alter_enum_stmt>, 'AlterDefaultPrivilegesStmt': <function alter_default_privileges_stmt>, 'AlterFunctionStmt': <function alter_function_stmt>, 'AlterObjectSchemaStmt': <function alter_object_schema_stmt>, 'AlterOperatorStmt': <function alter_operator_stmt>, ('AlterOperatorStmt', 'DefElem'): <function alter_operator_stmt_def_elem>, 'AlterOpFamilyStmt': <function alter_op_family_stmt>, 'AlterOwnerStmt': <function alter_owner_stmt>, 'AlterPolicyStmt': <function alter_policy_stmt>, 'AlterRoleStmt': <function alter_role_stmt>, 'AlterSeqStmt': <function alter_seq_stmt>, 'AlterTableStmt': <function alter_table_stmt>, ('AlterTableStmt', 'RangeVar'): <function range_var>, 'AlterTableCmd': <function alter_table_cmd>, ('IntoClause', 'DefElem'): <function alter_table_cmd_def_elem>, ('IndexStmt', 'DefElem'): <function alter_table_cmd_def_elem>, ('CreateStmt', 'DefElem'): <function alter_table_cmd_def_elem>, ('CreatePublicationStmt', 'DefElem'): <function alter_table_cmd_def_elem>, ('AlterTableCmd', 'DefElem'): <function alter_table_cmd_def_elem>, 'AlterTSConfigurationStmt': <function alter_ts_configuration_stmt>, 'AlterTSDictionaryStmt': <function alter_ts_dictionary_stmt>, 'AlterStatsStmt': <function alter_stats_stmt>, 'AlterSubscriptionStmt': <function alter_subscription_stmt>, 'AlterPublicationStmt': <function alter_publication_stmt>, 'AlterFdwStmt': <function alter_fdw_stmt>, ('AlterFdwStmt', 'DefElem'): <function alter_fdw_stmt_def_elem>, 'AlterForeignServerStmt': <function alter_foreign_server_stmt>, 'AlterUserMappingStmt': <function alter_user_mapping_stmt>, 'AlterRoleSetStmt': <function alter_role_set_stmt>, 'AlterDomainStmt': <function alter_domain_stmt>, 'AlterEventTrigStmt': <function alter_event_trig_stmt>, 'AlterTypeStmt': <function alter_type_stmt>, 'CheckPointStmt': <function check_point_stmt>, 'ClusterStmt': <function cluster_stmt>, 'ColumnDef': <function column_def>, 'CommentStmt': <function comment_stmt>, 'CompositeTypeStmt': <function composite_type_stmt>, ('CompositeTypeStmt', 'RangeVar'): <function composite_type_stmt_range_var>, 'Constraint': <function constraint>, 'CreateAmStmt': <function create_am_stmt>, 'CreatedbStmt': <function create_db_stmt>, ('CreatedbStmt', 'DefElem'): <function create_db_stmt_def_elem>, 'CreateCastStmt': <function create_cast_stmt>, 'CreateConversionStmt': <function create_conversion_stmt>, 'CreateDomainStmt': <function create_domain_stmt>, 'CreateEnumStmt': <function create_enum_stmt>, 'CreateEventTrigStmt': <function create_event_trig_stmt>, ('CreateEventTrigStmt', 'DefElem'): <function create_event_trig_stmt_def_elem>, 'CreateExtensionStmt': <function create_extension_stmt>, ('CreateExtensionStmt', 'DefElem'): <function create_extension_stmt_def_elem>, 'CreateFdwStmt': <function create_fdw_stmt>, ('CreateFdwStmt', 'DefElem'): <function create_fdw_stmt_def_elem>, ('CreateUserMappingStmt', 'DefElem'): <function create_fdw_stmt_def_elem>, ('ColumnDef', 'DefElem'): <function create_fdw_stmt_def_elem>, 'CreateForeignServerStmt': <function create_foreign_server_stmt>, 'CreateForeignTableStmt': <function create_foreign_table_stmt>, ('CreateForeignServerStmt', 'DefElem'): <function create_foreign_table_stmt_def_elem>, ('CreateForeignTableStmt', 'DefElem'): <function create_foreign_table_stmt_def_elem>, 'CreateFunctionStmt': <function create_function_stmt>, ('AlterFunctionStmt', 'DefElem'): <function create_function_option>, ('CreateFunctionStmt', 'DefElem'): <function create_function_option>, ('DoStmt', 'DefElem'): <function create_function_option>, 'CreateOpClassStmt': <function create_opclass_stmt>, 'CreateOpClassItem': <function create_opclass_item>, 'CreateOpFamilyStmt': <function create_op_family_stmt>, 'CreatePLangStmt': <function create_plang_stmt>, 'CreatePolicyStmt': <function create_policy_stmt>, 'CreatePublicationStmt': <function create_publication_stmt>, ('CreatePublicationStmt', 'RangeVar'): <function create_publication_stmt_range_var>, 'CreateRangeStmt': <function create_range_stmt>, 'CreateRoleStmt': <function create_role_stmt>, ('CreateRoleStmt', 'DefElem'): <function create_or_alter_role_option>, ('AlterRoleStmt', 'DefElem'): <function create_or_alter_role_option>, 'CreateSchemaStmt': <function create_schema_stmt>, 'CreateSeqStmt': <function create_seq_stmt>, ('AlterSeqStmt', 'DefElem'): <function create_seq_stmt_def_elem>, ('CreateSeqStmt', 'DefElem'): <function create_seq_stmt_def_elem>, ('Constraint', 'DefElem'): <function create_seq_stmt_def_elem>, 'CreateStatsStmt': <function create_stats_stmt>, 'CreateStmt': <function create_stmt>, 'CreateTableAsStmt': <function create_table_as_stmt>, 'CreateTableSpaceStmt': <function create_table_space_stmt>, 'CreateTrigStmt': <function create_trig_stmt>, ('CreateSubscriptionStmt', 'DefElem'): <function create_subscription_stmt_stmt_def_elem>, ('AlterSubscriptionStmt', 'DefElem'): <function create_subscription_stmt_stmt_def_elem>, 'CreateSubscriptionStmt': <function create_subscription_stmt>, 'CurrentOfExpr': <function current_of_expr>, 'CreateTransformStmt': <function create_transform_stmt>, 'ClosePortalStmt': <function close_portal_stmt>, 'CreateUserMappingStmt': <function create_user_mapping_stmt>, 'DeallocateStmt': <function deallocate_stmt>, 'DefineStmt': <function define_stmt>, 'DefElem': <function def_elem>, ('DefineStmt', 'DefElem'): <function define_stmt_def_elem>, 'DiscardStmt': <function discard_stmt>, 'DoStmt': <function do_stmt>, 'DropdbStmt': <function drop_db_stmt>, 'DropOwnedStmt': <function drop_owned_stmt>, 'DropRoleStmt': <function drop_role_stmt>, 'DropStmt': <function drop_stmt>, 'DropSubscriptionStmt': <function drop_subscription_stmt>, 'DropTableSpaceStmt': <function drop_table_space_stmt>, 'DropUserMappingStmt': <function drop_user_mapping_stmt>, 'FunctionParameter': <function function_parameter>, 'GrantStmt': <function grant_stmt>, 'GrantRoleStmt': <function grant_role_stmt>, 'ImportForeignSchemaStmt': <function import_foreign_schema_stmt>, 'IndexStmt': <function index_stmt>, 'LockStmt': <function lock_stmt>, 'NotifyStmt': <function notify_stmt>, 'ObjectWithArgs': <function object_with_args>, ('AlterObjectSchemaStmt', 'ObjectWithArgs'): <function alter_object_schema_stmt_object_with_args>, ('AlterOperatorStmt', 'ObjectWithArgs'): <function alter_operator_stmt_object_with_args>, ('AlterOwnerStmt', 'ObjectWithArgs'): <function alter_owner_stmt_object_with_args>, ('CommentStmt', 'ObjectWithArgs'): <function comment_stmt_object_with_args>, ('DropStmt', 'ObjectWithArgs'): <function drop_stmt_object_with_args>, 'PartitionBoundSpec': <function partition_bound_spec>, 'PartitionCmd': <function partition_cmd>, 'PartitionElem': <function partition_elem>, 'PartitionRangeDatum': <function partition_range_datum>, 'PartitionSpec': <function partition_spec>, 'ReindexStmt': <function reindex_stmt>, 'RenameStmt': <function rename_stmt>, ('RenameStmt', 'RangeVar'): <function rename_stmt_range_var>, 'ReplicaIdentityStmt': <function replica_identity_stmt>, 'RoleSpec': <function role_spec>, 'RuleStmt': <function rule_stmt_printer>, 'RefreshMatViewStmt': <function refresh_mat_view_stmt>, 'ReassignOwnedStmt': <function reassign_owned_stmt>, 'SecLabelStmt': <function sec_label_stmt>, 'TableLikeClause': <function table_like_clause>, 'TriggerTransition': <function trigger_transition>, 'VacuumStmt': <function vacuum_stmt>, ('VacuumStmt', 'DefElem'): <function vacuum_stmt_def_elem>, 'VacuumRelation': <function vacuum_relation>, 'VariableShowStmt': <function variable_show_statement>, 'ViewStmt': <function view_stmt>, ('ViewStmt', 'DefElem'): <function view_stmt_def_elem>, 'A_ArrayExpr': <function a_array_expr>, 'A_Const': <function a_const>, 'A_Expr': <function a_expr>, 'A_Indices': <function a_indices>, 'A_Indirection': <function a_indirection>, ('A_Indirection', 'A_Star'): <function a_indirection_a_star>, ('A_Indirection', 'ColumnRef'): <function a_indirection_column_ref>, ('A_Indirection', 'FuncCall'): <function a_indirection_func_call>, ('A_Indirection', 'String'): <function a_indirection_field>, 'A_Star': <function a_star>, 'Alias': <function alias>, 'BitString': <function bitstring>, 'BoolExpr': <function bool_expr>, 'BooleanTest': <function boolean_test>, 'CallStmt': <function call_stmt>, 'CaseExpr': <function case_expr>, 'CaseWhen': <function case_when>, 'CoalesceExpr': <function coalesce_expr>, 'CollateClause': <function collate_clause>, 'ColumnRef': <function column_ref>, 'CommonTableExpr': <function common_table_expr>, 'ConstraintsSetStmt': <function constraints_set_stmt>, 'CopyStmt': <function copy_stmt>, ('CopyStmt', 'DefElem'): <function copy_stmt_def_elem>, 'DeclareCursorStmt': <function declare_cursor_stmt>, 'DeleteStmt': <function delete_stmt>, 'ExecuteStmt': <function execute_stmt>, 'ExplainStmt': <function explain_stmt>, ('ExplainStmt', 'DefElem'): <function explain_stmt_def_elem>, 'FetchStmt': <function fetch_stmt>, 'Float': <function float>, 'FuncCall': <function func_call>, ('FuncCall', 'WindowDef'): <function func_call_window_def>, 'GroupingSet': <function grouping_set>, 'GroupingFunc': <function grouping_func>, 'IndexElem': <function index_elem>, 'InferClause': <function infer_clause>, 'Integer': <function integer>, 'InsertStmt': <function insert_stmt>, 'IntoClause': <function into_clause>, 'JoinExpr': <function join_expr>, 'LockingClause': <function locking_clause>, 'ListenStmt': <function listen_stmt>, 'MinMaxExpr': <function min_max_expr>, 'MultiAssignRef': <function multi_assign_ref>, 'NamedArgExpr': <function named_arg_expr>, 'Null': <function null>, 'NullTest': <function null_test>, 'ParamRef': <function param_ref>, 'PrepareStmt': <function prepare_stmt>, 'OnConflictClause': <function on_conflict_clause>, 'RangeFunction': <function range_function>, 'RangeSubselect': <function range_subselect>, 'RangeTableFunc': <function range_table_func>, ('RangeTableFunc', 'ResTarget'): <function range_table_func_res_target>, 'RangeTableFuncCol': <function range_table_func_col>, 'RangeVar': <function range_var>, 'RangeTableSample': <function range_table_sample>, 'RawStmt': <function raw_stmt>, 'ResTarget': <function res_target>, 'RowExpr': <function row_expr>, 'SelectStmt': <function select_stmt>, 'SetToDefault': <function set_to_default>, 'SortBy': <function sort_by>, 'SQLValueFunction': <function sql_value_function>, 'String': <function string>, 'SubLink': <function sub_link>, 'TransactionStmt': <function transaction_stmt>, ('TransactionStmt', 'DefElem'): <function transaction_stmt_def_elem>, 'TruncateStmt': <function truncate_stmt>, 'TypeCast': <function type_cast>, 'TypeName': <function type_name>, 'UpdateStmt': <function update_stmt>, 'UnlistenStmt': <function unlisten_stmt>, 'VariableSetStmt': <function variable_set_stmt>, 'WithClause': <function with_clause>, 'WindowDef': <function window_def>, ('OnConflictClause', 'ResTarget'): <function update_stmt_res_target>, ('UpdateStmt', 'ResTarget'): <function update_stmt_res_target>, 'XmlExpr': <function xml_expr>, 'XmlSerialize': <function xml_serialize>}

Registry of specialized printers, keyed by their tag.

pglast.printers.SPECIAL_FUNCTIONS = {'pg_catalog.btrim': <function btrim>, 'pg_catalog.date_part': <function date_part>, 'pg_catalog.ltrim': <function ltrim>, 'pg_catalog.normalize': <function normalize>, 'pg_catalog.overlaps': <function overlaps>, 'pg_catalog.overlay': <function overlay>, 'pg_catalog.pg_collation_for': <function pg_collation_for>, 'pg_catalog.position': <function position>, 'pg_catalog.rtrim': <function rtrim>, 'pg_catalog.substring': <function substring>, 'pg_catalog.timezone': <function timezone>, 'pg_catalog.xmlexists': <function xmlexists>}

Registry of specialized function printers, keyed by their qualified name.

exception pglast.printers.PrinterAlreadyPresentError

Exception raised trying to register another function for a tag already present.

pglast.printers.get_printer_for_node_tag(parent_node_tag, node_tag)

Get specific printer implementation for given node_tag.

If there is a more specific printer for it, when it’s inside a particular parent_node_tag, return that instead.

pglast.printers.node_printer(*node_tags, override=False, check_tags=True)

Decorator to register a specific printer implementation for given node_tag.

Parameters
  • *node_tags – one or two node tags

  • override (bool) – when True the function will be registered even if already present in the NODE_PRINTERS registry

  • check_tags (bool) – by default each node_tags is checked for validity, that is must be a valid class implemented by pglast.ast; pass False to disable the check

When node_tags contains a single item then the decorated function is the generic one, and it will be registered in NODE_PRINTERS with that key alone. Otherwise it must contain two elements: the first may be either a scalar value or a sequence of parent tags, and the function will be registered under the key (parent_tag, tag).

pglast.printers.special_function(name, override=False)

Decorator to declare a particular PostgreSQL function name as special, with a specific printer.

Parameters
  • name (str) – the qualified name of the PG function

  • override (bool) – when True the function will be registered even if already present in the SPECIAL_FUNCTIONS registry