Re: possible to create multivalued index from xpath() results in 8.3?

Поиск
Список
Период
Сортировка
От Matt Magoffin
Тема Re: possible to create multivalued index from xpath() results in 8.3?
Дата
Msg-id 51496.192.168.1.108.1195615155.squirrel@msqr.us
обсуждение исходный текст
Ответ на Re: possible to create multivalued index from xpath() results in 8.3?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: possible to create multivalued index from xpath() results in 8.3?
Список pgsql-general
> AFAICT that's exactly what it does.
>
> regression=#  select xpath('//foo[@key="mykey"]/text()', '<value>ABC<foo
> key="mykey">XYZ</foo></value><foo key="mykey">RST</foo><foo>DEF</foo>');
>    xpath
> -----------
>  {XYZ,RST}
> (1 row)
>
> regression=#
>
> Of course this is of type xml[], but you can cast to text[] and then
> index.

Ugh, you're right of course! Somehow I had this wrong. So I tried to
create an index on the xml[] result by casting to text[] but I got the
"function must be immutable" error. Is there any reason the xml[] to
text[] cast is not immutable?

I worked around it by writing a function like

CREATE OR REPLACE FUNCTION xpath_to_text(xml_array xml[]) RETURNS text[] AS
$BODY$
BEGIN
    RETURN xml_array::text[];
END;
$BODY$
LANGUAGE 'plpgsql' IMMUTABLE;

and wrapping my CREATE INDEX call with that, like:

create index type_flag_idx on lead using gin (
    (xpath_to_text(xpath('/element[@key="foo"]/text()', xml)))
);

-- m@

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: PostgreSQL is not behaving consistently across platforms
Следующее
От: Tom Lane
Дата:
Сообщение: Re: possible to create multivalued index from xpath() results in 8.3?