Re: proposal casting from XML[] to int[], numeric[], text[]

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Nikolay Samokhvalov" <samokhvalov(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal casting from XML[] to int[], numeric[], text[]
Date: 2007-11-11 20:33:08
Message-ID: 162867790711111233h68cf5f86g62c009ca6ea42fdb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/11/2007, Nikolay Samokhvalov <samokhvalov(at)gmail(dot)com> wrote:
>
>
> On Sep 25, 2007 10:57 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> > Hello
> >
> > Current result from xpath function isn't indexable. It cannot be
> > problem with possibility cast it to some base types.
> >
> > CREATE OR REPLACE FUNCTION xml_list_to_int(xml[])
> > RETURNS int[] AS $$
> > SELECT ARRAY(SELECT to_number(($1[i])::text,'999999.99')::int
> > FROM generate_series(1, array_upper($1,1)) g(i))
> > $$ LANGUAGE SQL IMMUTABLE;
> >
> >
> > CREATE CAST (xml[] AS int[]) WITH FUNCTION xml_list_to_int(xml[]);
> >
> > -- now I can build functional index
> > CREATE INDEX fx ON foo USING
> > GIN((xpath('//id/text()',objednavka_v_xml)::int[]));
> >
> > Does anybody know better solution?
> >
>
> Alternative (and maybe better) approach would be:
> - create comparison functions that work in the same way as string
> comparison functions do (currently, it's straight forward since XML is
> stored as string);
> - do NOT create comparison operators to avoid explicit comparing XML values
> (to follow standard ways to work with XML and to avoid possible unexpected
> behaviors);
> - create opclass based on these functions and, therefore, obtain GIN
> indexes support for xml[];
> - describe in the docs, that one can use GIN indexes over XPath
> expressions, but should be aware that comparison with non-trivial XML
> constants have to be used carefully because of possible problems with
> whitespaces, etc (in other words, comparison here is doing letter by letter,
> as for varchar).
>
> If there are no objections I'll send patch for this.
>
It's good proposal. So only this is solution for indexing. I belive so
casting from xml[] to any others (mainly varchar[] and numeric[] can
be usefull.

Regards
Pavel

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-11-11 21:59:02 Re: proposal casting from XML[] to int[], numeric[], text[]
Previous Message Nikolay Samokhvalov 2007-11-11 20:06:10 Re: proposal casting from XML[] to int[], numeric[], text[]