Skip to content

feat: add support for the XMLTABLE table function - #2458

Open
fudianchn wants to merge 2 commits into
JSQLParser:masterfrom
fudianchn:feat/xmltable-2326
Open

feat: add support for the XMLTABLE table function#2458
fudianchn wants to merge 2 commits into
JSQLParser:masterfrom
fudianchn:feat/xmltable-2326

Conversation

@fudianchn

Copy link
Copy Markdown
Contributor

Fixes #2326.

XMLTABLE (SQL/XML standard, supported by PostgreSQL and Oracle) projects an XML document into a relational row set. JSQLParser currently fails to parse it, e.g. the PostgreSQL manual example:

SELECT x.*
  FROM xmldata,
       XMLTABLE('//ROWS/ROW'
                PASSING data
                COLUMNS id int PATH '@id',
                        ordinality FOR ORDINALITY,
                        country_id text PATH 'COUNTRY_ID',
                        size_sq_km float PATH 'SIZE[@unit = "sq_km"]') x

It is the XML counterpart of JSON_TABLE and shares its PASSING/COLUMNS structure, so this mirrors the existing JsonTableFunction:

  • a new XmlTableFunction AST node: a row XPath expression, an optional PASSING value [AS name], ... clause, and an optional COLUMNS clause with name FOR ORDINALITY or name <type> [PATH expr] [DEFAULT expr] per column;
  • an XmlTableBody branch in the TableFunction dispatch;
  • wired into ExpressionVisitor, ExpressionDeParser, ExpressionVisitorAdapter, TablesNamesFinder and ExpressionValidator.

The JSON-specific clauses (wrapper, error/empty handling, plan, NESTED) are intentionally out of scope, and XMLNAMESPACES would be a natural follow-up.

Testing

  • New XmlTableTest with parameterised parse/deparse round-trips (incl. the issue example, quoted column names, bracket XPath, DEFAULT, multiple PASSING arguments) plus AST assertions on the column structure.
  • ./gradlew test --tests net.sf.jsqlparser.expression.XmlTableTest is green; the full suite shows no new failures vs. master.
  • ./gradlew spotlessCheck passes.

XMLTABLE (SQL/XML standard, supported by PostgreSQL and Oracle) turns an
XML document into a relational row set. It is the XML counterpart of
JSON_TABLE and shares its PASSING/COLUMNS structure, so it mirrors the
existing JsonTableFunction without the JSON-specific clauses.

Adds an XmlTableFunction AST node plus a grammar branch in the
TableFunction dispatch covering:
- a row XPath expression
- an optional PASSING clause (value [AS name], ...)
- an optional COLUMNS clause with FOR ORDINALITY, data type, PATH and
  DEFAULT per column

Round-trips through parse/deparse and is wired into the expression
visitor, deparser, table-names finder and validator.

Fixes JSQLParser#2326

Signed-off-by: 付典 <fudianchn@gmail.com>
@fudianchn
fudianchn force-pushed the feat/xmltable-2326 branch from ad1d746 to 6752cc6 Compare August 8, 2026 19:13
Each inner class declared an empty public no-arg constructor as its only
constructor, which is redundant — the compiler generates an equivalent default
constructor (Codacy PMD UnnecessaryConstructor). Removed both; the grammar and
tests that instantiate them with `new ...Clause()` are unaffected. Verified
locally: full build + XmlTableTest pass on JDK 17; javap confirms the default
constructor is still synthesized.

Refs JSQLParser#2326

Signed-off-by: 付典 <fudianchn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] JSQLParser 5.4-SNAPSHOT : PostgreSQL : XMLTable function not supported

1 participant