Skip site navigation (1) Skip section navigation (2)

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

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: proposal casting from XML[] to int[], numeric[], text[]
Date: 2007-09-25 07:57:50
Message-ID: 162867790709250057i3e54c8e3v9459b2c5b8defd58@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
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?

Regards
Pavel Stehule

Responses

pgsql-hackers by date

Next:From: Peter EisentrautDate: 2007-09-25 08:15:26
Subject: Re: GUC variable renaming, redux
Previous:From: Chuck McDevittDate: 2007-09-25 07:10:41
Subject: Re: Suggestion for MSVC build

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group