Re: Index on array element

From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Index on array element
Date: 2003-11-25 15:35:36
Message-ID: 8765h81mwn.fsf@stark.dyndns.tv
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Steve Crawford <scrawford(at)pinpointresearch(dot)com> writes:

> How can I create an index on an array element? I seem to recall having
> done this in the past but I don't recall how.
>
> steve=# \d foo
> Table "public.foo"
> Column | Type | Modifiers
> -----------+--------+-----------
> textarray | text[] |
>
> steve=# create index foodex on foo (textarray[3]);
> ERROR: parser: parse error at or near "[" at character 38
>
> steve=# select version();
> PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3
> 20030226 (prerelease) (SuSE Linux)

In 7.3 you'll have to create a function to make this index.

create function first(text[]) returns text language sql as 'select $1 [1]' strict immutable;

then you can create an index like

create index foodex on foo (first(textarray));

In 7.4 you can do arbitrary expressions, but in 7.3 you can only do simple
function calls of a single column.

--
greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Matthew T. O'Connor 2003-11-25 16:14:34 Re: patch for pg_autovacuum
Previous Message Andrew Sullivan 2003-11-25 15:29:54 Re: PGSQL on shared hosting