Re: element from an array by its index

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Sam Mason <sam(at)samason(dot)me(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: element from an array by its index
Date: 2009-07-21 18:29:12
Message-ID: b42b73150907211129h4a6da399xb6465324266483ef@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jul 21, 2009 at 10:47 AM, Sam Mason<sam(at)samason(dot)me(dot)uk> wrote:
> On Tue, Jul 21, 2009 at 04:08:51PM +0600, Murat Kabilov wrote:
>> I would like to know if there is a function that extracts an element by its
>> index from an array?
>
> No, the syntax most people expect and use would be arr[ndx].  If you
> want a function, it would be easy to do:
>
>  CREATE FUNCTION array_index(anyarray,int)
>      RETURNS anyelement IMMUTABLE
>      LANGUAGE sql AS $$
>    SELECT $1[$2]; $$;

but, why would you write a function to do this?

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2009-07-21 19:28:34 Re: suggestion: log_statement = sample
Previous Message Merlin Moncure 2009-07-21 18:27:19 Re: commercial adaptation of postgres