Received: from megazone.bigpanda.com ([63.150.15.178]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fB22N7m80124 for ; Sat, 1 Dec 2001 21:23:07 -0500 (EST) (envelope-from sszabo@megazone23.bigpanda.com) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id EADD5D5F1; Sat, 1 Dec 2001 18:23:10 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id DE89A5BED; Sat, 1 Dec 2001 18:23:10 -0800 (PST) Date: Sat, 1 Dec 2001 18:23:10 -0800 (PST) From: Stephan Szabo To: Anthony Bouvier Cc: Subject: Re: Unexpected Return from Function In-Reply-To: Message-ID: <20011201182212.R74581-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200112/3 X-Sequence-Number: 5826 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.