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

Many thanks for clearing that one up.
I have avoided using arrays for the mean time and gone for the more elegant
solution of using an additional table. More flexible and powerful but, in the
simple case that I needed, meant more work... Roll on 7.4 !

Regards
Donald Fraser.

----- Original Message -----
From: "Joe Conway" <mail@joeconway.com>
To: "Donald Fraser" <demolish@cwgsy.net>
Cc: "[ADMIN]" <pgsql-admin@postgresql.org>
Sent: Thursday, July 17, 2003 6:50 PM
Subject: Re: [ADMIN] Arrays in pl/pgsql functions


> 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: <00ab01c34c8e$ba682400$1664a8c0@DEMOLITION>
Permalink:  ../00ab01c34c8e$ba682400$1664a8c0@DEMOLITION/
Also on:    postgresql.org/message-id/00ab01c34c8e$ba682400$1664a8c0@DEMOLITION

 · 

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: demolish@cwgsy.net
  Subject: Re: Arrays in pl/pgsql functions
  In-Reply-To: <00ab01c34c8e$ba682400$1664a8c0@DEMOLITION>
  References: <005701c34c55$8d017540$1664a8c0@DEMOLITION> <3F16E1D5.7080304@joeconway.com> <00ab01c34c8e$ba682400$1664a8c0@DEMOLITION>

* 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