Re: possible to create multivalued index from xpath() results in 8.3? - Mailing list pgsql-general

From Matt Magoffin
Subject Re: possible to create multivalued index from xpath() results in 8.3?
Date
Msg-id 53241.192.168.1.108.1195498831.squirrel@msqr.us
Whole thread Raw
In response to Re: possible to create multivalued index from xpath() results in 8.3?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: possible to create multivalued index from xpath() results in 8.3?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
> "Matt Magoffin" <postgresql.org@msqr.us> writes:
>> 2) Even if I could have an xpath() result return an array with multiple
>> values, like {value1,value2,value3} I wasn't able to define a GIN index
>> against the xml[] type. Should this be possible?
>
> Dunno about your other questions, but the answer to this one is "no"
> --- AFAICS there is no indexing support of any kind for the xml type
> in 8.3.  Try casting to text[] instead.

I had tried that, but it does not actually work because of my first issue,
of a way for the XPath to return 3 individual text nodes. If I return 3
elements, like

/elem[@key="mykey"] => {
  <elem key="mykey">value1</elem>,
  <elem key="mykey">value2</elem>,
  <elem key="mykey">value3</elem>
}

and cast that to text[], I get 3 XML strings, including the <elem></elem>.
I want only the element text content.

Should the xpath() function return 3 individual text nodes like this:

/elem[@key="mykey"]/text() => {
  value1,
  value2,
  value3
}

rather than concatenating these into a single text node result? I also
tried something like

string(/elem[@key="mykey"])

but that throws an XPath error. It looks like the code is converting this
to /x/string(/elem[@key="mykey"] internally, which is not a valid XPath.

So if xpath() cannot return individual text node results, would a possible
solution be to write a trigger function that generates a tsvector from the
XML array, and then use text search to locate matches?

-- m@

pgsql-general by date:

Previous
From: "Josh Harrison"
Date:
Subject: Re: postgresql storage and performance questions
Next
From: "Kynn Jones"
Date:
Subject: Foreign keys and inheritance