Re: arrays and pl/pgsql?

From: Brandon Craig Rhodes <brandon(at)oit(dot)gatech(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: arrays and pl/pgsql?
Date: 2003-02-13 19:50:27
Message-ID: w6wuk4rmd8.fsf@guinness.ts.gatech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Richard Welty <rwelty(at)averillpark(dot)net> writes:

> given the lack of response, i'm going to presume that there is no published
> material on arrays and pl/pgsql
>
> can someone please 1) clearly state on whether arrays work in pl/pgsql and
> 2) if they do, please explain the syntax?

In PL/pgSQL you can declare arrays, set the value of arrays, and
reference array members; I have not discovered any way of setting
individual array members without having to re-set the entire array.

An example procedure follows:

CREATE FUNCTION try_array() RETURNS INTEGER AS '
DECLARE
array INTEGER[];
number INTEGER;
BEGIN
array := ''{3,4,6}'';
number := array[1];
RAISE NOTICE ''First element is %'', number;
number := array[2];
RAISE NOTICE ''Second element is %'', number;
number := array[3];
RAISE NOTICE ''Third element is %'', number;
array := ''{3,4,12}'';
number := array[3];
RAISE NOTICE ''Third element is now %'', number;
RETURN NULL;
END;
' LANGUAGE 'plpgsql';

--
Brandon Craig Rhodes http://www.rhodesmill.org/brandon
Georgia Tech brandon(at)oit(dot)gatech(dot)edu

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dennis Gearon 2003-02-13 20:03:10 using serial values
Previous Message Stephan Szabo 2003-02-13 19:34:12 Re: index scan with index cond on first column doesn't