Re: Using XMLNAMESPACES with XMLEMENT

From: Garfield Lewis <garfield(dot)lewis(at)lzlabs(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using XMLNAMESPACES with XMLEMENT
Date: 2021-09-26 19:48:37
Message-ID: D8FDDCCF-92A1-4D7F-8335-DA812ECC35F2@lzlabs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thx @Pavel Stehule<mailto:pavel(dot)stehule(at)gmail(dot)com>, I’ll see if I can figure this out… ☺

Regards,
Garfield

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Date: Friday, September 24, 2021 at 11:33 PM
To: Garfield Lewis <garfield(dot)lewis(at)lzlabs(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using XMLNAMESPACES with XMLEMENT

Hi

pá 24. 9. 2021 v 23:44 odesílatel Garfield Lewis <garfield(dot)lewis(at)lzlabs(dot)com<mailto:garfield(dot)lewis(at)lzlabs(dot)com>> napsal:
Hi All,

I am attempting to port the following statement from DB2z to Postgres:

SELECT e.empno, e.firstnme, e.lastname,

XMLELEMENT ( NAME "foo:Emp",

XMLNAMESPACES('http://www.foo.com' AS "foo"),

XMLATTRIBUTES(e.empno as "serial"),

e.firstnme,

e.lastname ) AS "Result"

FROM EMP e

WHERE e.edlevel = 12;

The NAMESPACES function is not supported by Postgres in the XMLELEMENT function. Is there any way to get this to work? I’ve looked at the WITH syntax but it doesn’t look like that will be helpful here.

I am afraid this is not supported in Postgres. The XMLNAMESPACE clause can be used only in XMLTABLE function. You need to make XML and in the next step you need to modify it as string with string operation.

It can be an interesting feature, and if it is supported by libxml2, then it can be easily implemented. But at this moment it is unsupported, and you have to use string operations - it should not be hard to use regexp.

Regards

Pavel

Regards,
Garfield

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lucas Possamai 2021-09-26 23:06:10 PostgreSQL 9.2 high replication lag - Part 2
Previous Message Pavel Stehule 2021-09-25 03:32:48 Re: Using XMLNAMESPACES with XMLEMENT