Re: arrays and pl/pgsql? - Mailing list pgsql-general

From Brandon Craig Rhodes
Subject Re: arrays and pl/pgsql?
Date
Msg-id w6wuk4rmd8.fsf@guinness.ts.gatech.edu
Whole thread Raw
In response to Re: arrays and pl/pgsql?  (Richard Welty <rwelty@averillpark.net>)
List pgsql-general
Richard Welty <rwelty@averillpark.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@oit.gatech.edu

pgsql-general by date:

Previous
From: Egyud Csaba
Date:
Subject: Fw: set returning functions in v7.3
Next
From: Dennis Gearon
Date:
Subject: using serial values