View Single Post

   
  #4 (permalink)  
Old 04-17-2008, 09:29 PM
Oisin Glynn
 
Posts: n/a
Default Returning a long string (varchar from a function)

I have a function that I am using to provide results back to a program.

I want/need to pass a long string approx. 400chars back from this.

I am getting cut off at 256...

Any way around this. I would be greatful for any help. Below is a dummy
function showing the error.It should return a long list of 'aaaaaa'with the
number of a's appended to the end.

select * from zfunc_test(7);
'aaaaaaa7'


select * from zfunc_test(254);
Gets chopped off to '...aaaa25'



-- Function: zfunc_test(int4)

-- DROP FUNCTION zfunc_test(int4);

CREATE OR REPLACE FUNCTION zfunc_test(int4)
RETURNS "varchar" AS
$BODY$DECLARE

v_length integer;
v_retval varchar;
v_counter integer;

BEGIN
v_length = $1;
v_counter =0;
v_retval :='';
WHILE v_counter < v_length LOOP
v_retval := v_retval || 'a';
v_counter:=v_counter +1;
END LOOP;
v_retval :=v_retval || CAST(v_length as VARCHAR);
return v_retval;
END;


$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION zfunc_test(int4) OWNER TO postgres;



---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Reply With Quote