Skip to content

Conversation

@harshdubey166
Copy link
Contributor

@harshdubey166 harshdubey166 commented Jun 10, 2025

Description

To add support for Openxml with WITH clause, this PR exposes wrapper hooks to facilitate support for T-SQL OPENXML functionality by allowing babelfish to customize XML table processing during query parsing.

Added two new hooks:

  • pre_transform_openxml_columns_hook , to allow extensions to pre-process OPENXML column definitions
    before standard XMLTABLE transformation.
  • openxml_set_namespaces_hook, which fetches and register namespaces in xpath context.

Extensions PR : babelfish-for-postgresql/babelfish_extensions#3820

Signed-off-by: Harsh Dubey [email protected]
Authored by : Harsh Dubey [email protected]

Issues Resolved

BABEL-3635, BABEL 6045

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the PostgreSQL license, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@harshdubey166 harshdubey166 changed the title Added support for openxml with WITH clause Added support for OPENXML with WITH clause Jun 15, 2025
Signed-off-by: Harsh Dubey <[email protected]>
Harsh Dubey added 2 commits September 17, 2025 13:04
Copy link
Contributor

@Deepesh125 Deepesh125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update description

@Deepesh125 Deepesh125 merged commit 8d438f9 into babelfish-for-postgresql:BABEL_5_X_DEV__PG_17_X Sep 24, 2025
2 checks passed
Deepesh125 pushed a commit to babelfish-for-postgresql/babelfish_extensions that referenced this pull request Sep 24, 2025
OPENXML provides a rowset view over an XML document. Since OPENXML is a rowset provider and it returns a set of
rows, we can use OPENXML in the FROM clause of a TSQL query just as we can use any other table, view, or table-
valued function. The WITH clause in OPENXML provides a rowset format (and additional mapping information as
required) by using either SchemaDeclaration or specifying an existing TableName.

Primary objective of this commit is to add support for OPENXML with WITH clause.

The syntax of openxml is as follows :

OPENXML ( idoc int [ in ] , rowpattern nvarchar [ in ], [ flags byte [ in ] ] )
    [ WITH ( SchemaDeclaration | TableName ) ]

Arguments:
idoc - The document handle of the internal representation of an XML document. The internal representation of an XML
document is created by calling sp_xml_preparedocument.
rowpattern - The XPath pattern used to identify the nodes to be processed as rows. The nodes come from the XML
document whose handle is passed in the idoc parameter.
flags - Indicates the mapping used between the XML data and the relational rowset, and how the spill-over column is
filled. flags is an optional input parameter.

The WITH clause provides a rowset format (and additional mapping information as required) by using either
SchemaDeclaration or specifying an existing TableName. If the optional WITH clause isn't specified, the results are
returned in an edge table format. Edge tables represent the fine-grained XML document structure (such as
element/attribute names, the document hierarchy, the namespaces, PIs, and so on) as a single table.

Engine PR : babelfish-for-postgresql/postgresql_modified_for_babelfish#587

Task: BABEL-3635, BABEL-6045
Signed-off-by: Harsh Dubey <[email protected]>
Vineetha125 pushed a commit to amazon-aurora/babelfish_extensions that referenced this pull request Sep 25, 2025
OPENXML provides a rowset view over an XML document. Since OPENXML is a rowset provider and it returns a set of
rows, we can use OPENXML in the FROM clause of a TSQL query just as we can use any other table, view, or table-
valued function. The WITH clause in OPENXML provides a rowset format (and additional mapping information as
required) by using either SchemaDeclaration or specifying an existing TableName.

Primary objective of this commit is to add support for OPENXML with WITH clause.

The syntax of openxml is as follows :

OPENXML ( idoc int [ in ] , rowpattern nvarchar [ in ], [ flags byte [ in ] ] )
    [ WITH ( SchemaDeclaration | TableName ) ]

Arguments:
idoc - The document handle of the internal representation of an XML document. The internal representation of an XML
document is created by calling sp_xml_preparedocument.
rowpattern - The XPath pattern used to identify the nodes to be processed as rows. The nodes come from the XML
document whose handle is passed in the idoc parameter.
flags - Indicates the mapping used between the XML data and the relational rowset, and how the spill-over column is
filled. flags is an optional input parameter.

The WITH clause provides a rowset format (and additional mapping information as required) by using either
SchemaDeclaration or specifying an existing TableName. If the optional WITH clause isn't specified, the results are
returned in an edge table format. Edge tables represent the fine-grained XML document structure (such as
element/attribute names, the document hierarchy, the namespaces, PIs, and so on) as a single table.

Engine PR : babelfish-for-postgresql/postgresql_modified_for_babelfish#587

Task: BABEL-3635, BABEL-6045
Signed-off-by: Harsh Dubey <[email protected]>
Yvinayak07 pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Oct 16, 2025
…abelfish-for-postgresql#587)

To add support for Openxml with WITH clause, this commit exposes wrapper hooks to facilitate support for T-SQL
OPENXML functionalities by allowing Babelfish to customised XML table processing during query parsing.

Added two new hooks:
1. pre_transform_openxml_columns_hook , to allow extensions to pre-process OPENXML column definitions
before standard XMLTABLE transformation.
2. openxml_set_namespaces_hook, which fetches and register namespaces in xpath context.

Extensions PR : babelfish-for-postgresql/babelfish_extensions#3820

Task: BABEL-3635, BABEL 6045
Signed-off-by: Harsh Dubey <[email protected]>
Yvinayak07 pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Oct 16, 2025
…abelfish-for-postgresql#587)

To add support for Openxml with WITH clause, this commit exposes wrapper hooks to facilitate support for T-SQL
OPENXML functionalities by allowing Babelfish to customised XML table processing during query parsing.

Added two new hooks:
1. pre_transform_openxml_columns_hook , to allow extensions to pre-process OPENXML column definitions
before standard XMLTABLE transformation.
2. openxml_set_namespaces_hook, which fetches and register namespaces in xpath context.

Extensions PR : babelfish-for-postgresql/babelfish_extensions#3820

Task: BABEL-3635, BABEL 6045
Signed-off-by: Harsh Dubey <[email protected]>
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.

5 participants