From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Anthony Bouvier <anthony@developware.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Unexpected Return from Function
Date: Sat, 1 Dec 2001 18:23:10 -0800 (PST)
Message-ID: <20011201182212.R74581-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <CBEBKIKGCCOCPDEMKBBJMEPHCAAA.anthony@developware.com>
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.
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sszabo@megazone23.bigpanda.com, anthony@developware.com
Subject: Re: Unexpected Return from Function
In-Reply-To: <20011201182212.R74581-100000@megazone23.bigpanda.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