I need to change the value of an XML attribute stored in a column using the XML datatype in a table before I return it to the client.
Right now I use a cursor, get xml, cast it to VARCHAR, parse it, change the attribute value (or add it if it is not present), put it in temporary table and return data from temporary table. Everything is done in a stored procedure (pl/pgsql).
I wonder if there is cleaner way to do this?
You can use XML::LibXML in a PL/PerlU function (or PL/Perl, if you can preload XML::LibXML in
plperl.on_initin yourpostgresql.conf) like this:Then you can use it like so:
There is quite a bit of flexibility to be had in the XPath expression to
findnodes(), in case you need more than that.