Is there a bug in FOR i IN 1..10 LOOP (8.4.4)?

Started by Nickover 15 years ago3 messagesgeneral
Jump to latest
#1Nick
nboutelier@gmail.com

CREATE FUNCTION test() RETURNS text
LANGUAGE plpgsql
AS $$DECLARE
num_var TEXT;
BEGIN
FOR i IN 1..10 LOOP
num_var := num_var || ',' || i;
END LOOP;
RETURN num_var;
END;$$;

SELECT test();

returns NULL

#2Nick
nboutelier@gmail.com
In reply to: Nick (#1)
Re: Is there a bug in FOR i IN 1..10 LOOP (8.4.4)?

Woops, figured it out. Just needed to declare the num_var := '';

Show quoted text

On Sep 11, 10:45 pm, Nick <nboutel...@gmail.com> wrote:

CREATE FUNCTION test() RETURNS text
    LANGUAGE plpgsql
    AS $$DECLARE
  num_var TEXT;
BEGIN
  FOR i IN 1..10 LOOP
    num_var := num_var || ',' || i;
  END LOOP;
  RETURN num_var;
END;$$;

SELECT test();

returns NULL

#3Rob Richardson
Rob.Richardson@rad-con.com
In reply to: Nick (#1)
Re: Is there a bug in FOR i IN 1..10 LOOP (8.4.4)?

What makes you think there is a bug? What does this function return for
you? It always helps us to see everything you have seen.

Without taking the time to try it on my system, I'd recommend explictly
converting your index to text:
num_var := num_var || ',' || i::text;

RobR