3

PostgreSQL Version 9.1,

i have a table,

xmltest=# \d xmltest
    Table "public.xmltest"
 Column  |  Type   | Modifiers 
---------+---------+-----------
 id      | integer | not null
 xmldata | xml     | 
Indexes:
    "xmltest_pkey" PRIMARY KEY, btree (id)

xmltest=# select * from xmltest;
 id |                xmldata                
----+---------------------------------------
  1 | <root>                               +
    | <child1>somedata for child1 </child1>+
    | <child2>somedata for child2 </child2>+
    | </root> 
(1 row)

now how to update the value inside the element/tag child2,

i don't prefer to update the whole column at once,

is their a way to do update/add/delete that particular value of tag, if so please share :)

MAHI
  • 9,263
  • 11
  • 36
  • 47

1 Answers1

2

PostgreSQL XML functions are aimed a producing and processing XML, not so much at manipulating it, I am afraid.

You can extract values with xpath(), there are a number of functions to build XML, but I would not know of built-in functionality to update elements inside a given XML value.

Community
  • 1
  • 1
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228