From 1b0187063855519394139d9b88b2d9d696adb201 Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Fri, 23 Sep 2016 16:06:51 +0800 Subject: [PATCH] Docs and test updates to xmltable --- doc/src/sgml/func.sgml | 89 ++++++++++++++++++++++++++++++++++++++++---- src/test/regress/sql/xml.sql | 22 ++++++++++- 2 files changed, 101 insertions(+), 10 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index f6bead6..3292fcd 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -10368,7 +10368,7 @@ SELECT xml_is_well_formed_document(' and + ' are left unchanged. This means that 'apos; + and 'quot; entities in XML input get expanded in xml + output columns. There is no way to prevent their expansion. If the path expression does not match for a given row but a DEFAULT expression is specified, the resulting default value is used. If no DEFAULT is given the - field will be NULL. + field will be NULL. Unlike normal queries, it is possible for + a DEFAULT expression to reference the value of output columns + that appear prior to it in the column-list, so the default of one + column may be based on the value of another column. @@ -10492,6 +10550,22 @@ SELECT * to null then the function terminates with an ERROR. + + + Unlike normal PostgreSQL functions, the PATH and + DEFAULT arguments to xmltable are not evaluated + to a simple value before calling the function. PATH + expressions are normally evaluated exactly once per result row + , and DEFAULT expressions each time a default is + needed for a field. If the expression qualifies as stable or immutable + the repeat evaluation may be skipped. Effectively xmltable + behaves more like a subquery than a function call. This means that you + can usefully use volatile functions like nextval in + DEFAULT expressions, your PATH expressions may + depend on other parts of the XML document, etc. + + + A column marked with the FOR ORDINALITY keyword will be populated with @@ -10502,8 +10576,7 @@ SELECT * - Empty tag is translated as empty string (possible attribute xsi:nil - has not any effect. The XPath expression in PATH clause is evaluated + The XPath expression in PATH clause is evaluated for any input row. The expression in DEFAULT expression is evaluated for any missing value (for any output row). diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index b67af31..60529fc 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -393,8 +393,26 @@ SELECT xmltable.* FROM xmldata, LATERAL xmltable('/ROWS/ROW[COUNTRY_NAME="Japan" SELECT xmltable.* FROM xmldata, LATERAL xmltable('/ROWS/ROW[COUNTRY_NAME="Japan" or COUNTRY_NAME="India"]' PASSING data COLUMNS id int PATH '@id', "COUNTRY_NAME" text, "REGION_ID" int, rawdata xml PATH '.'); SELECT xmltable.* FROM xmldata, LATERAL xmltable('/ROWS/ROW[COUNTRY_NAME="Japan" or COUNTRY_NAME="India"]' PASSING data COLUMNS id int PATH '@id', "COUNTRY_NAME" text, "REGION_ID" int, rawdata xml PATH './*'); -SELECT * FROM xmltable('/root' passing 'a1aa2abbbbxxxcccc' COLUMNS element text); -SELECT * FROM xmltable('/root' passing 'a1aa2abbbbxxxcccc' COLUMNS element text PATH 'element/text()'); -- should fail +SELECT * FROM xmltable('/root' passing 'a1aa2a bbbbxxxcccc' COLUMNS element text); +SELECT * FROM xmltable('/root' passing 'a1aa2a bbbbxxxcccc' COLUMNS element text PATH 'element/text()'); -- should fail + +-- XML builtin entities +SELECT * FROM xmltable('/x/a' PASSING ''"&<>' COLUMNS ent text); +SELECT * FROM xmltable('/x/a' PASSING ''"&<>' COLUMNS ent xml); + +-- Undefined entities (no DTD) +SELECT * FROM xmltable('/x/a' PASSING ' ' COLUMNS ent text); +SELECT * FROM xmltable('/x/a' PASSING ' ' COLUMNS ent xml); + +-- Defined entities (inline DTD) + +SELECT * FROM xmltable('/' PASSING $XML$ + + +]> +Hello &pg;. +$XML$ COLUMNS foo text); EXPLAIN (VERBOSE, COSTS OFF) SELECT xmltable.* -- 2.5.5