Re: Unexpected Return from Function

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Anthony Bouvier <anthony(at)developware(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Unexpected Return from Function
Date: 2001-12-02 02:23:10
Message-ID: 20011201182212.R74581-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, 1 Dec 2001, Anthony Bouvier wrote:

> I have a FUNCTION:
>
> CREATE FUNCTION get_responsible(text)
> RETURNS TEXT AS '
> DECLARE
> responsible_list text;
> my_record RECORD;
> BEGIN
> FOR my_record IN SELECT login FROM employee WHERE id IN (1,2) LOOP
> responsible_list := responsible_list || '', '' my_record.login;
> END LOOP;
> RETURN responsible_list;
> END;
> ' LANGUAGE 'plpgsql';
>
> The employee table is such:
>
> id | login
> -------------
> 1 | anthony
> 2 | mary
> -------------
>
> I expect the SQL statement "SELECT get_responsible('1,2')" to return
> something like so:
>
> get_responsible
> ---------------
> anthony, mary
> ---------------
>
> But instead I receive:
>
> get_responsible
> ---------------
>
> ---------------

You probably need to initialize responsible_list to an empty string.
My guess is that it starts NULL and NULL concatenated with anything
is still NULL.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Horst Herb 2001-12-02 07:44:04 Re: problems with single quotes..
Previous Message Anthony Bouvier 2001-12-02 02:00:35 Unexpected Return from Function