Fault when return strings over 256 characters in PLpgSQL function

From: cathy(dot)hemsley(at)powerconv(dot)alstom(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: Fault when return strings over 256 characters in PLpgSQL function
Date: 2005-03-09 11:11:46
Message-ID: OFC8F55579.F9AF1E76-ON80256FBF.003C83B1-80256FBF.003DF259@transport.alstom.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I have a PLpgSQL function that returns a string (varchar): if this string
is over 256 characters long then the last three characters are corrupted:
replaced by the string ' (.'

This is my test function:-

-- Function: testconverttousername(varchar, varchar)
DROP FUNCTION testconverttousername();
CREATE OR REPLACE FUNCTION testconverttousername()
RETURNS varchar AS
-- RETURNS text AS
'
DECLARE
userName varchar (1000); -- have tried without (1000) but makes
no difference
locn int;
BEGIN
userName := \'12345678\';
userName := userName || userName; -- 16 chars
userName := userName || userName; -- 32 chars
userName := userName || userName; -- 64 chars
userName := userName || userName; -- 128 chars
userName := userName || userName; --256 chars
userName := userName || \'88\'; --258 chars
-- userName has now "788" at end replaced with " (." ? Test
this...apparently not...
locn := position(\'.\' in userName);
IF locn > 0 THEN
--userName has now "788" at end replaced with " (." ? Test
this...apparently not...
userName := \'Has got additional character . put in it \';
END IF;
RETURN userName; -- has "7888" at end replaced with " (." so fault is at
the return statement??
END
'
LANGUAGE 'plpgsql' STABLE;

This function returns a string that should end with '7888' but ends with
'78 (.'. As far as I can see returning text or varchar makes no
difference, and the corruption occurs at the RETURN statement, not before.
The fault only occurs if the string is over 256 characters.

I am using Postgres 8.0.0 latest release on a Windows 2000 server.
Your help would be appreciated, as this is causing some problems!
Cathy

:.________________
CONFIDENTIALITY : This e-mail and any attachments are confidential and
may be privileged. If you are not a named recipient, please notify the
sender immediately and do not disclose the contents to another person, use
it for any purpose or store or copy the information in any medium.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Neil Conway 2005-03-09 11:56:20 Re: Fault when return strings over 256 characters in PLpgSQL
Previous Message Ezequiel Tolnay 2005-03-09 02:09:22 BUG #1532: typecast problem between arrays of an int8 derived datatype and varchar[]