Package: pglast
Author:Lele GaifaxContact:lele@metapensiero.itLicense:GNU General Public License version 3 or laterStatus:Version:6This is a Python 3 module that exposes theparse treeof aPostgreSQLstatement (extracted
by the almost standard PG parser repackaged as a standalone static library bylibpg_query)
as set of interconnectednodes, usually called anabstract syntax tree.See amore detailed introductionin thedocumentation.InstallationAs usual, the easiest way is with pip:$ pip install pglastAlternatively you can clone the repository:$ git clone https://github.com/lelit/pglast.git --recursiveand install from there:$ pip install ./pglastDevelopmentThere is a set ofmakefilesimplementing the most common operations, amake helpwill
show a brief table of contents. A comprehensive test suite, based onpytest,coversnearly
99% of the source lines.DocumentationLatest documentation is hosted byRead the Docsathttps://pglast.readthedocs.io/en/v6ChangesVersion 66.2 (2024-02-01)Almost no-op release to fix issue144, producing correct wheels for macOS arm646.1 (2024-01-22)Inherit fix for issue143fromversion 56.0 (2024-01-22)Produce wheels for macOS arm646.0.dev2 (2024-01-21)Enable compilation on Windows and produce related 32bit and 64bit wheels (issue#7)6.0.dev1 (2024-01-11)Re-enable Linux 32bit wheels, thanks to libpg_query to16-5.1.06.0.dev0 (2023-12-29)No visible changes with respect to v5, apart from the support for new/revised syntaxes ofPostgreSQL 16Do not build binary wheels for Python 3.8Skip compilation on Linux 32bit (seethis commentfor details)Breaking changesTarget PostgreSQL 16, thanks to libpg_query16-5.0.0Version 55.9 (2024-01-22)Fix issue143, affectingAlterOwnerStmtandRenameStmtprinters5.8 (2024-01-11)Fix issue#142, a glitch that affected 32-bit systems5.7 (2023-12-23)UseCython 3.0.7Update libpg_query to15-4.2.45.6 (2023-12-07)Fix issue#138, a defect that hindered the creation of AST nodes that act asmarkers,
(currentlyA_StarandCheckPointStmt), that do not carry any other informationUseCython 3.0.6Handle theENABLE TRIGGER ALLinAlterTableCmdFix issue#136, a regression introduced by “Avoid overly abundancy of parentheses in
expressions”5.5 (2023-10-07)UseCython 3.0.3Produce wheels using final Python 3.12 release, thanks tocibuildwheel2.16.25.4 (2023-08-24)Improve documentation, addingparser.Displacements,parser.scanandparser.splitexamples (issue #128)Fix issues#129and#130(merged fromversion 4.4)5.3 (2023-08-05)Update libpg_query to15-4.2.35.2 (2023-05-20)Update libpg_query to15-4.2.15.1 (2023-02-28)Mergeversion 4.2changes5.0 (2023-02-19)No changes5.0.dev1 (2023-02-11)Update libpg_query to15-4.2.0Breaking changesChange the type of theast.Floatvalue fromDecimaltostrUsing aDecimalimplies potential differences in the representation of floating numbers,
and already caused issues (#91and#100) in the past, making it impossible to render,
say,SELECT 0.0e1, due to the fact thatDecimal('0.0e1')resolves toDecimal('0').5.0.dev0 (2022-12-19)No visible changes with respect to v4, apart from the support for new/revised syntaxes ofPostgreSQL 15Breaking changesTarget PostgreSQL 15, thanks to libpg_query15-4.0.0Version 44.5 (unreleased)UseCython 3.0.24.4 (2023-08-24)Fix issues#129and#130(merged fromversion 3.18)4.3 (2023-04-27)Fixserialization issuewhen column’sDEFAULTvalue is an expression4.2 (2023-02-27)Handle special syntax required bySET TIME ZONE INTERVAL'-08:00'hour to minuteFix mistype mapping of raw C “long” and “double” attributes, that were decorated with the
wrong Python type4.1 (2022-12-19)Fix serialization glitches introduced by “Avoid overly abundancy of parentheses in
expressions” (to be precise, bythiscommit)4.0 (2022-12-12)Update libpg_query to final14-3.0.04.0.dev0 (2022-11-24)Update libpg_query to14-3.0.0Avoid overly abundancy of parentheses in expressionsPreferSELECT a FROM b LIMIT ALLto... LIMIT NONEBreaking changesTarget PostgreSQL 14The wrapper classes used in previous versions, implemented inpglast.node, are gone: now
everything works on top of theASTclasses (issue #80)TheAncestorclass is not iterable anymore: it was an internal implementation facility,
now moved to a_iter_members()methodVersion 33.18 (2023-08-24)FixBooleanTestprinter, enclosing expression within parens in more cases (issue
#129)FixConstraintprinter, avoiding repetition of “DEFERRABLE INITIALLY DEFERRED” on some
kind of constraints (issue #130)3.17 (2022-11-04)FixAlterSubscriptionStmtprinter, handling “SET PUBLICATION” without options3.16 (2022-11-03)Update libpg_query to13-2.2.03.15 (2022-10-17)Produce Python 3.11 wheels (PR #108), thanks tocibuildwheel2.11.1and to Bastien
Gandouet3.14 (2022-08-08)Harden the wayVisitorhandle modifications to the AST (issue #107)3.13 (2022-06-29)Update libpg_query to13-2.1.23.12 (2022-06-19)Rewrite the implementation of thereferenced_relations()function, that was flawed with
regard to CTEs handling (issue #106), thanks to Michal Charemza for providing his own
versionImproveWithClauseprinter indentationFix minor whitespace related issues in a few printer functions3.11 (2022-05-29)Fix theVisitorclass, it was ignoring nodes nested in sub-listsReduce the size of the generated parser by factoring out common code into helper functions3.10 (2022-05-11)Update libpg_query to13-2.1.1(PR #102), thanks to James GuthrieProducemusllinuxwheels, thanks tocibuildwheel2.5.0(PEP 656was actually
introduced in2.2.0)3.9 (2022-02-24)Fix bug handling node containing alocationfield, e.g.CreateTableSpaceStmt(issue
#98)Properly handle dereferenced array expression (issue #99)Avoid improper “floatification” of literal integers (issue #100)3.8 (2021-12-28)Fix glitch in the AST extractor tool (issue #97)Add Linux AArch64 wheel build support (PR #95), thanks to odidevFix type mismatch when using--remove-pg_catalog-from-functions(PR #93), thanks
to Boris Zentner3.7 (2021-10-13)Update libpg_query to13-2.1.03.6 (2021-10-09)Use latest libpg_query, to fix an error parsingPLpgSQLstatements (issue #88)3.5 (2021-09-26)Forward thespecial_functionsoption to substream, when concatenating items
(issue #89)Fix representation of floating point numbers without decimal digits (issue #91)Produce Python 3.10 wheels, thanks tocibuildwheel2.1.2Update libpg_query to13-2.0.7New option--remove-pg_catalog-from-functionson the command line tool (PR #90), thanks
to Boris ZentnerImplement morespecial functions(PR #92), thanks to Boris Zentner3.4 (2021-08-21)Fix another packaging issue, that prevented recompilation from the sdist.tar.gz(issue
#86), thanks to Christopher Brichford3.3 (2021-07-04)Update libpg_query to13-2.0.63.2 (2021-06-25)Effectively include libpg_query’s vendored sources (issue #82)3.1 (2021-06-25)Fix packaging glitch (issue #82)Build wheels also for macOSUpdate libpg_query to13-2.0.53.0 (2021-06-04)Fix glitch in theRawStream, avoiding spurious space after an open parenthesisImprove theVisitorclass, to make it easier altering the original treeProperly handle nested lists in the serialization of AST Node3.0.dev2 (2021-05-22)Fix bug inCreateStmtprinter (issue #79)Make it possible to pass also concreteast.Nodes toRawStream`Breaking changesTo reduce confusion, theprintermodule has been removed: print-specific stuff is now
directly exposed by theprinterssubpackage while serialization classes are now in the
newstreammoduleThe default value for thesafety_beltoption of theprintify()function is nowFalse3.0.dev1 (2021-05-16)FixAT_SetIdentity,AT_EnableReplicaTrigandAlterSubscriptionStmtprintersImproveAlterTSConfigTypeandIntoClauseprintersNew generic “visitor pattern” (issue #51) exemplified by a newreferenced_relations()function (issue #66)Refine printing of SQL commentsImplementAlterExtensionStmtprinter3.0.dev0 (2021-05-03)Expose the newpg_query_scan()function asparser.scan()Expose thepg_query_parse()function asparser.parse_sql_json()Expose the newpg_query_parse_protobuf()function asparser.parse_sql_protobuf()Expose the newpg_query_deparse_protobuf()function asparser.deparse_protobuf()Honor thecatalognameof aRangeVarif present (issue #71)Cover almost allSQLstatements, testing against the wholePostgreSQLregression
suite(issue #68,PR #72andPR #77), thanks to Ronan Dunklau and Hong ChengNew rudimentary support for thepreserve commentsfeature (issue #23)Breaking changesTarget PostgreSQL 13Thepglast.parsermodule exposes alllibpg_queryentry points, even the newpg_query_deparse_protobuf()function that is basically equivalent toRawStream-based printerThesplit()function is now based on the lower levelpg_query_split_with_xxx()functionsTheparse_sql()function returns native Python objects, not aJSONstring as before:
all PGnodesare now represented by subclasses ofpglast.ast.Node, without exception,
evenExprandValueare there. The latter impacts onpglast.node.Scalar: for
example it now may contains aast.Integerinstance instead of a PythonintThepgpp--parse-treeoutput is apprintrepresention of theAST, not aJSONstring as beforeTheParseErrorexception does not expose thelocationas an instance member anymore,
although its still there, as the second argument (ie.args[1]); furthermore, its value
now corresponds to the index in the original Unicode string, instead of the offset in theUTF-8representation passed to the underlying C functionVersion 22.0.dev3 (2021-02-20)HandleINCLUDEclause inIndexStmt(PR #67), thanks to Ronan Dunklau2.0.dev2 (2020-10-24)Merge newfingerprintfunctionality fromv1(i.e.master) branch2.0.dev1 (2020-09-26)Require Python 3.6 or greaterHandleALTER TYPE .. RENAME VALUEinAlterEnumStmt(PR #52), thanks to Ronan
DunklauAdd support for Create / Alter / Drop PROCEDURE (PR #48), thanks to Ronan DunklauUse Ronan’sforkof libpg_query, targeting PostgreSQL 12.1 (PR #36)Change get_postgresql_version() to return a(major, minor)tuple (issue #38)HandleALTER TABLE ... ALTER COLUMN ... SET STORAGE ...Handle PG12 materialized CTEs (issue #57)Support column numbers inALTER INDEX(PR #58), thanks to Ronan DunklauHandleSET LOGGEDandSET UNLOGGEDinALTER TABLE(PR #59), thanks to Ronan
DunklauHandleALTER TYPE ... RENAME(PR #62), , thanks to Ronan
DunklauVersion 11.18 (2021-06-01)Fix exclusion constraint printer (issue #81)1.17 (2021-02-20)Fix the generic case in theRenameStmtprinter1.16 (2021-02-20)Promote to thestablestateMove the job of building and uploading binary wheels from TravisCI to GitHub Actions1.15 (2021-02-19)FixIF EXISTSvariant ofRenameStmtprinter (PR #70), thanks to Jonathan
MortensenUpdate libpg_query to 10-1.0.51.14 (2020-10-24)Produce Python 3.9 wheels, thanks tocibuildwheel1.6.3Expose thelibpg_query’sfingerprintfunctionality (PR #64), thanks to Yiming
Wang1.13 (2020-09-26)HandleSELECT FROM foo1.12 (2020-06-08)Double quote column names in theTYPE_FUNC_NAME_KEYWORDSset (issue #55)Possibly wrapSELECTinUNION/INTERSECTbetween parens, when needed
(issue #55)1.11 (2020-05-08)FixA_Exprprinter, whenlexpris missing (PR #54), thanks to AihamSupportDISABLE ROW LEVEL SECURITYinAlterTableCmd(PR #49), thanks to Ronan
DunklauImplementCreateOpClassStmtprinter (PR #47), thanks to Ronan Dunklau1.10 (2020-01-25)Fix collation name printer (PR #44), thanks to Ronan DunklauImplementCreatePLangStmtprinter (PR #42), thanks to Bennie SwartFix privileges printer (PR #41), thanks to Bennie SwartHandleTRUNCATEevent inCreateTrigStmtprinter (PR #40), thanks to Bennie SwartFix function body dollar quoting (PR #39), thanks to Bennie Swart1.9 (2019-12-20)PrettierINSERTrepresentation1.8 (2019-12-07)PrettierCASErepresentationNew option to emit a semicolon after the last statement (issue #24)1.7 (2019-12-01)ImplementNotifyStmtprinterImplementRuleStmtprinter, thanks to Gavin M. Roy for hisPR #28FixRenameStmt, properly handling object nameProduce Python 3.8 wheels, thanks tocibuildwheel1.0.0SupportALTER TABLE RENAME CONSTRAINT(PR #35), thanks to Ronan Dunklau1.6 (2019-09-04)Fix issue with boolean expressions precedence (issue #29)ImplementBitStringprinterSupportLEAKPROOFoption (PR #31), thanks to Ronan DunklauSupportDEFERRABLE INITIALLY DEFERREDoption (PR #32), thanks to Ronan Dunklau1.5 (2019-06-04)Fix issue withRETURNS SETOFfunctions, a more general solution than the one proposed by
Ronan Dunklau (PR #22)Allow more than one empty line between statements (PR #26), thanks to apnewberry1.4 (2019-04-06)Fix wrap of trigger’s WHEN expression (issue #18)Support for variadic functions (PR #19), thanks to Ronan DunklauSupport ORDER / LIMIT / OFFSET for set operations (PR #20), thanks to Ronan DunklauImplementConstraintsSetStmtand improveVariableSetStmtprinters1.3 (2019-03-28)SupportCROSS JOINand timezone modifiers on time and timestamp datatypes (PR #15),
thanks to Ronan DunklauMany new printers and several enhancements (PR #14), thanks to Ronan DunklauExpose the package version as pglast.__version__ (issue #12)1.2 (2019-02-13)Implement newsplit()function (seePR #10)ImplementBooleanTestprinter (issue #11)1.1 (2018-07-20)No visible changes, but now PyPI carries binary wheels for Python 3.7.1.0 (2018-06-16)ImportantThe name of the package has been changed frompg_querytopglast, to
satisfy the request made by the author oflibpg_queryinissue #9.This affects both the main repository on GitHub, that from now on ishttps://github.com/lelit/pglast, and the ReadTheDocs project that hosts the
documentation,http://pglast.readthedocs.io/en/latest/.I’m sorry for any inconvenience this may cause.0.28 (2018-06-06)Update libpg_query to 10-1.0.2Support the ‘?’-style parameter placeholder variant allowed by libpg_query (details)0.27 (2018-04-15)Prettier JOINs representation, aligning them with the starting relation0.26 (2018-04-03)Fix cosmetic issue with ANY() and ALL()0.25 (2018-03-31)Fix issue in the safety belt check performed bypgpp(issue #4)0.24 (2018-03-02)ImplementNullprinter0.23 (2017-12-28)Implement some other DDL statements printersNew alternative style to printcomma-separated-valueslists, activated by a new--comma-at-eolnoption onpgpp0.22 (2017-12-03)ImplementTransactionStmtand almost allDROP xxxprinters0.21 (2017-11-22)ImplementNamedArgExprprinterNew alternative printers for a set ofspecial functions, activated by a new--special-functionsoption onpgpp(issue #2)0.20 (2017-11-21)Handle special de-reference (A_Indirection) cases0.19 (2017-11-16)Fix serialization of column labels containing double quotesFix corner issues surfaced implementing some more DDL statement printers0.18 (2017-11-14)Fix endless loop due to sloppy conversion of command line optionInstall the command line tool aspgpp0.17 (2017-11-12)Rename printers.sql to printers.dml (backward incompatibility)List printer functions in the documentation, referencing the definition of related node typeFix inconsistent spacing in JOIN condition inside a nested expressionFix representation of unbound arraysFix representation ofintervaldata typeInitial support for DDL statementsFix representation of string literals containing single quotes0.16 (2017-10-31)Update libpg_query to 10-1.0.00.15 (2017-10-12)Fix indentation of boolean expressions in SELECT’s targets (issue #3)0.14 (2017-10-09)Update to latest libpg_query’s 10-latest branch, targeting PostgreSQL 10.0 final0.13 (2017-09-17)Fix representation of subselects requiring surrounding parens0.12 (2017-08-22)New option--versionon the command line toolBetter enums documentationRelease the GIL while calling libpg_query functions0.11 (2017-08-11)Nicer indentation for JOINs, making OUTER JOINs stand outMinor tweaks to lists rendering, with less spurious whitespacesNew option--no-locationon the command line tool0.10 (2017-08-11)Support Python 3.4 and Python 3.5 as well as Python 3.60.9 (2017-08-10)Fix spacing before the $ characterHandle type modifiersNew option--plpgsqlon the command line tool, just for fun0.8 (2017-08-10)Add enums subpackages to the documentation with references to their related headersNewcompact_lists_marginoption to produce a more compact representation when possible
(seeissue #1)0.7 (2017-08-10)Fix sdist including the Sphinx documentation0.6 (2017-08-10)New option--parse-treeon the command line tool to show just the parse treeSphinx documentation, available online0.5 (2017-08-09)Handle some more cases when a name must be double-quotedComplete the serialization of the WindowDef node, handling its frame options0.4 (2017-08-09)Expose the actual PostgreSQL version the underlying libpg_query libray is built on thru a newget_postgresql_version()functionNew optionsafety_beltfor theprettify()function, to protect the innocentsHandle serialization ofCoalesceExprandMinMaxExpr0.3 (2017-08-07)Handle serialization ofParamRefnodesExpose aprettify()helper function0.2 (2017-08-07)Test coverage at 99%First attempt at automatic wheel upload to PyPI, let’s see…0.1 (2017-08-07)First release (“Hi daddy!”, as my soul would tag it)