Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 907841337999 for ; Mon, 14 Feb 2011 23:08:51 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 69856-07 for ; Tue, 15 Feb 2011 03:08:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from milan.hostgo.com (milan.hostgo.com [72.52.99.130]) by mail.postgresql.org (Postfix) with ESMTP id 1D6AA1336971 for ; Mon, 14 Feb 2011 23:08:43 -0400 (AST) Received: from [217.10.134.34] (helo=[192.168.1.71]) by milan.hostgo.com with esmtpa (Exim 4.69) (envelope-from ) id 1PkKbt-00035S-Lo; Tue, 01 Feb 2011 13:05:50 -0500 Message-ID: <4D484B7A.4060209@mlfowler.com> Date: Tue, 01 Feb 2011 18:05:46 +0000 From: Mike Fowler User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: Alexandre CC: pgsql-bugs@postgresql.org Subject: Re: BUG #5859: XML result in line and column References: <201102011520.p11FKpLt022295@wwwmaster.postgresql.org> In-Reply-To: <201102011520.p11FKpLt022295@wwwmaster.postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - milan.hostgo.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mlfowler.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201102/129 X-Sequence-Number: 29401 On 01/02/11 15:20, Alexandre wrote: > The following bug has been logged online: > > Bug reference: 5859 > Logged by: Alexandre > Email address: ultrago@gmail.com > PostgreSQL version: 8.4.7 > Operating system: Windows 7 > Description: XML result in line and column > Details: > > The name of the xml tag is not being updated, becoming the first name > registry for all. Here is example: > > Create table AUDITORIA_ANTERIOR > ( > SEQUENCIA Serial NOT NULL, > SEQUENCIA_AUDITORIA Integer NOT NULL, > REGISTRO Text NOT NULL, > primary key (SEQUENCIA,SEQUENCIA_AUDITORIA) > ); > > insert into auditoria_anterior (sequencia_auditoria, registro) > values (1, ' > 123456789011 O_CONVENIO>FJOAO DA > SILVA ') > > SELECT * FROM > xpath_table('sequencia', > 'registro', > 'auditoria_anterior', > 'name(/ROOT/CLIENTES/*)|/ROOT/CLIENTES/*', > 'sequencia = 1') > AS t(sequencia integer, coluna text, valor text) > > --Incorrect result----------------------------------- > sequencia coluna valor > integer text text > -------------------------------------------------- > 1 CGC_CPF_CLIENTE 12345678901 > 1 CGC_CPF_CLIENTE 1 > 1 CGC_CPF_CLIENTE F > 1 CGC_CPF_CLIENTE JOAO DA SILVA > Yep, I can duplicate this under Linux. However this is not a bug in xpath_table. The problem is your XPath statement - the function name() always returns the element name of the first element in a list. See http://www.w3.org/TR/xpath/#section-Node-Set-Functions for details. Unfortunately the only way to achieve what you want with with XPath 2.0 or XQuery, but libxslt (the underlying library executing the XPath) does not and does not plan to support XPath 2.0 and PostgreSQL won't support XQuery any time soon (http://wiki.postgresql.org/wiki/XML_Support#Future_Projects). Regards, -- Mike Fowler Registered Linux user: 379787