CREATE EXTENSION seg;

DROP TABLE IF EXISTS xmldata CASCADE;

CREATE TABLE xmldata AS SELECT
xml $$
<ROWS>
  <ROW id="1">
    <LOC>0 .. 1</LOC>
    <COUNTRY_NAME>Australia</COUNTRY_NAME>
  </ROW>
  <ROW id="5">
    <LOC>0 .. 4</LOC>
    <COUNTRY_NAME>Japan</COUNTRY_NAME>
  </ROW>
</ROWS>
$$ AS data;

CREATE VIEW xmlview AS
SELECT xmltable.id, "LOC"::text
  FROM xmldata,
       XMLTABLE('//ROWS/ROW'
                PASSING data
                COLUMNS id int PATH '@id',
                        "COUNTRY_NAME" text,
                        "LOC" seg);

SELECT * FROM xmlview;

DROP EXTENSION seg;

SELECT * FROM xmlview;
