-
Notifications
You must be signed in to change notification settings - Fork 137
It's not possible to use the XMLTABLE() function with PostgreSQL #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for the detailed report ! I opened an issue upstream: apache/datafusion-sqlparser-rs#1816 |
In the meantime, the easiest way for you to work around the problem is to define your own user-defined function in postgres that wraps xmltable, but does not require any special syntax. Then you can call your own function instead of xmltable from SQLPage. CREATE OR REPLACE FUNCTION parse_xml_rows(xml_data xml)
RETURNS TABLE (
id int,
ordinality int,
country_name text,
country_id text,
size_sq_km float,
size_other text,
premier_name text
) AS $$
BEGIN
RETURN QUERY
SELECT
x.id,
x.ordinality,
x."COUNTRY_NAME",
x.country_id,
x.size_sq_km,
x.size_other,
x.premier_name
FROM XMLTABLE(
'//ROWS/ROW'
PASSING xml_data
COLUMNS
id int PATH '@id',
ordinality FOR ORDINALITY,
"COUNTRY_NAME" text,
country_id text PATH 'COUNTRY_ID',
size_sq_km float PATH 'SIZE[@unit = "sq_km"]',
size_other text PATH 'concat(SIZE[@unit!="sq_km"], " ", SIZE[@unit!="sq_km"]/@unit)',
premier_name text PATH 'PREMIER_NAME' DEFAULT 'not specified'
) AS x;
END;
$$ LANGUAGE plpgsql; |
Yes, that's a good idea. It's a temporary solution to the problem. In the short term, a stored procedure solves the SQL parser problem. |
Good news. My implementation has been merged upstream, xmltable() is coming to the next version of sqlpage :) |
Hi.
I need to use the XML functions of PostgreSQL for parsing XML data. My problem is when I want use the XMLTABLE() function (https://www.postgresql.org/docs/15/functions-xml.html). The parsing of the SQL code by SQLPage fails.
You can reproduce the bug with the following example :
I got a sqlPage error message :
The expected behavior is that the temporary table should contain :
Thank you for your help
Best regards
Olivier
The text was updated successfully, but these errors were encountered: