UNICODE and PL/PGSQL - Mailing list pgsql-sql

From Bart Degryse
Subject UNICODE and PL/PGSQL
Date
Msg-id 456AD17A020000300000FB60@webaccess.indicator.be
Whole thread Raw
Responses Re: UNICODE and PL/PGSQL
List 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
 

pgsql-sql by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: select into
Next
From: Markus Schaber
Date:
Subject: Re: PgAgent [where is it?]