pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Donald Fraser <demolish@cwgsy.net>
Cc: [ADMIN] <pgsql-admin@postgresql.org>
Subject: Re: Arrays in pl/pgsql functions
Date: Thu, 17 Jul 2003 10:50:13 -0700
Message-ID: <3F16E1D5.7080304@joeconway.com> (raw)
In-Reply-To: <005701c34c55$8d017540$1664a8c0@DEMOLITION>
References: <005701c34c55$8d017540$1664a8c0@DEMOLITION>

Donald Fraser wrote:
> Could someone be please inform me what the correct syntax for accessing arrays
> is or tell me if its not possible with pl/pgSQL functions.
> 

It won't work in 7.3.x or before, as you've noted. In 7.4 this will work:

CREATE OR REPLACE FUNCTION test_arrays() RETURNS int4[] AS '
DECLARE
      test int4[] := ''{}'';
BEGIN
     test[1] := 1;
     RETURN test;
END ' LANGUAGE 'plpgsql';

regression=# select test_arrays();
  test_arrays
-------------
  {1}
(1 row)

Note that you have to initialize "test" to an empty array, because 
otherwise you are trying to add an element to a NULL::int4[], the result 
of which is still NULL.

Joe




view thread (4+ messages)  latest in thread

Message-ID: <3F16E1D5.7080304@joeconway.com>
Permalink:  ../3F16E1D5.7080304@joeconway.com/
Also on:    postgresql.org/message-id/3F16E1D5.7080304@joeconway.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mail@joeconway.com, demolish@cwgsy.net
  Subject: Re: Arrays in pl/pgsql functions
  In-Reply-To: <3F16E1D5.7080304@joeconway.com>
  References: <005701c34c55$8d017540$1664a8c0@DEMOLITION> <3F16E1D5.7080304@joeconway.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox