API documentation¶
This chapter briefly explains some implementation detail.
- exception pglast.Error¶
Top level error exception.
- pglast.__author__ = 'Lele Gaifax <lele@metapensiero.it>'¶
Package’s author.
- pglast.__version__ = 'v4.4'¶
Package’s version.
- pglast.prettify(statement, safety_belt=False, preserve_comments=False, **options)¶
Render given statement into a prettified format.
- Parameters
statement (str) – the SQL statement(s)
safety_belt (bool) – whether to perform a safe check against bugs in pglast’s serialization
preserve_comments (bool) – whether comments shall be preserved, defaults to not
**options – any keyword option accepted by
IndentedStream
constructor
- Returns
a string with the equivalent prettified statement(s)
When safety_belt is
True
, the resulting statement is parsed again and its AST compared with the original statement: if they don’t match, a warning is emitted and the original statement is returned. By default it isFalse
, so no double check is done.
- pglast.split(stmts, with_parser=True, only_slices=False)¶
Split the given stmts string into a sequence of the single
SQL
statements.By default this uses the parser to perform the job; when with_parser is
False
the scanner variant is used, indicated when the statements may contain parse errors.When only_slices is
True
, return a sequence ofslice
instances, one for each statement, instead of statements text.NB: leading and trailing whitespace are removed from the statements.
pglast.parser
— The interface with libpg_querypglast.ast
— Python classes representing PG parser nodesNode
Value
BitString
Float
Integer
Null
String
A_ArrayExpr
A_Const
A_Expr
A_Indices
A_Indirection
A_Star
AccessPriv
Aggref
Alias
AlterCollationStmt
AlterDatabaseSetStmt
AlterDatabaseStmt
AlterDefaultPrivilegesStmt
AlterDomainStmt
AlterEnumStmt
AlterEventTrigStmt
AlterExtensionContentsStmt
AlterExtensionStmt
AlterFdwStmt
AlterForeignServerStmt
AlterFunctionStmt
AlterObjectDependsStmt
AlterObjectSchemaStmt
AlterOpFamilyStmt
AlterOperatorStmt
AlterOwnerStmt
AlterPolicyStmt
AlterPublicationStmt
AlterRoleSetStmt
AlterRoleStmt
AlterSeqStmt
AlterStatsStmt
AlterSubscriptionStmt
AlterSystemStmt
AlterTSConfigurationStmt
AlterTSDictionaryStmt
AlterTableCmd
AlterTableMoveAllStmt
AlterTableSpaceOptionsStmt
AlterTableStmt
AlterTypeStmt
AlterUserMappingStmt
AlternativeSubPlan
ArrayCoerceExpr
ArrayExpr
BoolExpr
BooleanTest
CTECycleClause
CTESearchClause
CallContext
CallStmt
CaseExpr
CaseTestExpr
CaseWhen
CheckPointStmt
ClosePortalStmt
ClusterStmt
CoalesceExpr
CoerceToDomain
CoerceToDomainValue
CoerceViaIO
CollateClause
CollateExpr
ColumnDef
ColumnRef
CommentStmt
CommonTableExpr
CompositeTypeStmt
Constraint
ConstraintsSetStmt
ConvertRowtypeExpr
CopyStmt
CreateAmStmt
CreateCastStmt
CreateConversionStmt
CreateDomainStmt
CreateEnumStmt
CreateEventTrigStmt
CreateExtensionStmt
CreateFdwStmt
CreateForeignServerStmt
CreateForeignTableStmt
CreateFunctionStmt
CreateOpClassItem
CreateOpClassStmt
CreateOpFamilyStmt
CreatePLangStmt
CreatePolicyStmt
CreatePublicationStmt
CreateRangeStmt
CreateRoleStmt
CreateSchemaStmt
CreateSeqStmt
CreateStatsStmt
CreateStmt
CreateSubscriptionStmt
CreateTableAsStmt
CreateTableSpaceStmt
CreateTransformStmt
CreateTrigStmt
CreateUserMappingStmt
CreatedbStmt
CurrentOfExpr
DeallocateStmt
DeclareCursorStmt
DefElem
DefineStmt
DeleteStmt
DiscardStmt
DoStmt
DropOwnedStmt
DropRoleStmt
DropStmt
DropSubscriptionStmt
DropTableSpaceStmt
DropUserMappingStmt
DropdbStmt
ExecuteStmt
ExplainStmt
FetchStmt
FieldSelect
FieldStore
FromExpr
FuncCall
FuncExpr
FunctionParameter
GrantRoleStmt
GrantStmt
GroupingFunc
GroupingSet
ImportForeignSchemaStmt
IndexElem
IndexStmt
InferClause
InferenceElem
InlineCodeBlock
InsertStmt
IntoClause
JoinExpr
ListenStmt
LoadStmt
LockStmt
LockingClause
MinMaxExpr
MultiAssignRef
NamedArgExpr
NotifyStmt
NullTest
ObjectWithArgs
OnConflictClause
OnConflictExpr
OpExpr
PLAssignStmt
Param
ParamRef
PartitionBoundSpec
PartitionCmd
PartitionElem
PartitionRangeDatum
PartitionSpec
PrepareStmt
Query
RangeFunction
RangeSubselect
RangeTableFunc
RangeTableFuncCol
RangeTableSample
RangeTblEntry
RangeTblFunction
RangeTblRef
RangeVar
RawStmt
ReassignOwnedStmt
RefreshMatViewStmt
ReindexStmt
RelabelType
RenameStmt
ReplicaIdentityStmt
ResTarget
ReturnStmt
RoleSpec
RowCompareExpr
RowExpr
RowMarkClause
RuleStmt
SQLValueFunction
ScalarArrayOpExpr
SecLabelStmt
SelectStmt
SetOperationStmt
SetToDefault
SortBy
SortGroupClause
StatsElem
SubLink
SubPlan
SubscriptingRef
TableFunc
TableLikeClause
TableSampleClause
TargetEntry
TransactionStmt
TriggerTransition
TruncateStmt
TypeCast
TypeName
UnlistenStmt
UpdateStmt
VacuumRelation
VacuumStmt
Var
VariableSetStmt
VariableShowStmt
ViewStmt
WindowClause
WindowDef
WindowFunc
WithCheckOption
WithClause
XmlExpr
XmlSerialize
pglast.enums
— Enumerated constantspglast.keywords
— Various kinds of PostgreSQL keywordspglast.stream
— The serialization machinerypglast.printers
— Specialized printer functionspglast.printers.sfuncs
— Special function printerspglast.visitors
— Other ways to inspect and manipulate the AST