Re: function returning array - Mailing list pgsql-sql

From Joe Conway
Subject Re: function returning array
Date
Msg-id 407EB3DF.6010304@joeconway.com
Whole thread Raw
In response to Re: function returning array  ("Dennis" <pg-user@calico-consulting.com>)
Responses Re: function returning array  ("Dennis" <pg-user@calico-consulting.com>)
List 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



pgsql-sql by date:

Previous
From: Christoph Haller
Date:
Subject: Re: Grant permission to all objects of user A to user B
Next
From: "Dennis"
Date:
Subject: Re: function returning array