Re: function returning array

From: Joe Conway <mail(at)joeconway(dot)com>
To: Dennis <pg-user(at)calico-consulting(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, postgres SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: function returning array
Date: 2004-04-15 16:10:07
Message-ID: 407EB3DF.6010304@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dennis wrote:
> pg 7.4.1
>
> I should have listed the source for the function. Here is a simplified
> parseString function and the foo that calls it.
>
> dennis=# create or replace function parseString (varchar, varchar)
> dennis-# RETURNS varchar[] AS '
> dennis'# DECLARE
> dennis'# pParsed varchar[];

Make that last line:
pParsed varchar[] := ''{}'';

That initializes pParsed to an *empty* array. Otherwise pParsed is NULL,
and when you attempt to extend a NULL array, e.g. "pParsed[1] =
''blah''" you still get NULL. It is similar to this:

regression=# select NULL || 'blah';
?column?
----------

(1 row)

HTH,

Joe

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2004-04-15 16:58:48 Re: Row count after SELECT INTO?
Previous Message Jan Wieck 2004-04-15 14:50:33 Re: cursors and for loops?