Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghZwn-0003fH-L4 for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jan 2019 13:00:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ghZwm-0005qu-Az for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jan 2019 13:00:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghZwl-0005ql-Rz for pgsql-hackers@lists.postgresql.org; Thu, 10 Jan 2019 13:00:32 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ghZwc-0006m0-K9 for pgsql-hackers@postgresql.org; Thu, 10 Jan 2019 13:00:30 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 5521421D8417; Thu, 10 Jan 2019 16:00:19 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.237] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 0497B21D7993; Thu, 10 Jan 2019 16:00:18 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1547125219; bh=1jooW2h/+ca3/O5bmo7hO9kZdxJli01IBxq6ZYaTzRs=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=TP0BoLJ53wJaoeJ6J/1T9Fx3j/voPNXXkDvo3+hxOCQV7wvRItKUYPQ9jLhIpox2R 0Yc+8DyEVz4Kw/JdsLbfTHpHu1ba5Xgu06By4sPHn7YZNDazHdsqB6CKBWARgJsqvY PWLfX0/zlp+yiPFQoCP9Gl+0n/s9i394j4OvqggQ= Subject: Re: PostgreSQL vs SQL/XML Standards To: Pavel Stehule , Markus Winand Cc: Alvaro Herrera , Chapman Flack , Tom Lane , PostgreSQL Hackers References: <20181025194720.ylmw64xqlnjr5wja@alvherre.pgsql> From: Arthur Zakirov Message-ID: <89664994-34c5-089b-dd28-68be2beb73c3@postgrespro.ru> Date: Thu, 10 Jan 2019 16:00:18 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------61730A8DD9D4069C1BB745EC" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------61730A8DD9D4069C1BB745EC Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello Pavel, On 09.11.2018 07:07, Pavel Stehule wrote: > I used your patch and append regress tests. I checked the result against > Oracle. I checked the patch with Chap cases. The patch fixes handling of boolean, number types which mentioned in the wiki. I have a few comments related to the code and the documentation. I attached the patch, which fixes it. There is an example in the documentation: SELECT xmltable.* FROM xmlelements, XMLTABLE('/root' PASSING data COLUMNS element text); element ---------------------- Hello2a2 bbbCC With the patch XMLTABLE returns different result now. copy_and_safe_free_xmlchar() function should be hid by #ifdef USE_LIBXML, otherwise I get an error if I build the Postgres without --with-libxml. There is a comment within XmlTableGetValue(). I changed it, mainly I used Markus patch from the related thread mentioned by Alvaro. Please see the changes in the patch. -- Arthur Zakirov Postgres Professional: http://www.postgrespro.com Russian Postgres Company --------------61730A8DD9D4069C1BB745EC Content-Type: text/x-patch; name="xmltable-xpath-result-review-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xmltable-xpath-result-review-fix.patch" diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 90d67f1acf..06f3f69073 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -10999,9 +10999,9 @@ $$ AS data; SELECT xmltable.* FROM xmlelements, XMLTABLE('/root' PASSING data COLUMNS element text); - element ----------------------- - Hello2a2 bbbCC + element +------------------------- + Hello2a2 bbbxxxCC ]]> diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index a83882f5de..df7f0cc20d 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -4427,6 +4427,7 @@ XmlTableFetchRow(TableFuncScanState *state) #endif /* not USE_LIBXML */ } +#ifdef USE_LIBXML /* * Copy XmlChar string to PostgreSQL memory. Ensure releasing of * source xmllib string. @@ -4455,6 +4456,7 @@ copy_and_safe_free_xmlchar(xmlChar *str) return result; } +#endif /* * XmlTableGetValue @@ -4504,9 +4506,9 @@ XmlTableGetValue(TableFuncScanState *state, int colnum, /* * There are four possible cases, depending on the number of nodes * returned by the XPath expression and the type of the target column: - * a) XPath returns no nodes. b) One node is returned, and column is - * of type XML. c) One node, column type other than XML. d) Multiple - * nodes are returned. + * a) XPath returns no nodes. b) The target type is XML (return all + * as XML). For non-XML types: c) One node (return content). + * d) Multiple nodes (error). */ if (xpathobj->type == XPATH_NODESET) { --------------61730A8DD9D4069C1BB745EC--