UNICODE and PL/PGSQL

From: "Bart Degryse" <Bart(dot)Degryse(at)indicator(dot)be>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: UNICODE and PL/PGSQL
Date: 2006-11-27 10:52:26
Message-ID: 456AD17A020000300000FB60@webaccess.indicator.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dear all,
This works: SELECT '\x65'; => it returns the letter 'e'.
When I do the following in PL/PGSQL it returns the same letter 'e' (as might be expected);

CREATE OR REPLACE FUNCTION "public"."myfunction" (out result varchar) RETURNS varchar AS
$body$
DECLARE
charset varchar := '';
BEGIN
charset := charset || '\x65';
result := charset;
RETURN;
END;
$body$
LANGUAGE 'plpgsql' IMMUTABLE RETURNS NULL ON NULL INPUT SECURITY INVOKER;

However, when I compose charset dynamically it doesn't work anymore. Following function returns 'x65' instead of 'e'.
Can anyone tell me why that is and how to make it work? The target is of course to change the values in the FOR control structure.

CREATE OR REPLACE FUNCTION "public"."myfunction" (out result varchar) RETURNS varchar AS
$body$
DECLARE
charset varchar := '';
BEGIN
FOR i IN 101..101 LOOP
charset := charset || '\x' || to_hex(i);
END LOOP;
result := charset;
RETURN;
END;
$body$
LANGUAGE 'plpgsql' IMMUTABLE RETURNS NULL ON NULL INPUT SECURITY INVOKER;

Thanks for any help.
Bart

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Markus Schaber 2006-11-27 13:48:06 Re: [SQL] PgAgent [where is it?]
Previous Message Adrian Klaver 2006-11-27 02:23:44 Re: select into