From f3bac31311dbff89e2f8683741c8a8aa492259a5 Mon Sep 17 00:00:00 2001 From: glyn Date: Wed, 12 Mar 2014 12:36:52 +0000 Subject: [PATCH] Added sql functions to check if we really need to do any conversion. --- codepage_850.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 codepage_850.sql diff --git a/codepage_850.sql b/codepage_850.sql new file mode 100644 index 0000000..4661a59 --- /dev/null +++ b/codepage_850.sql @@ -0,0 +1,17 @@ +DROP FUNCTION IF EXISTS public.decode_cp850(text); +CREATE OR REPLACE FUNCTION public.decode_cp850(text) +RETURNS text AS +$BODY$ + SELECT CASE WHEN $1 ~ '[^\x01-\x7F]' THEN cp850_to_utf8($1) ELSE $1 END; +$BODY$ +LANGUAGE sql IMMUTABLE; + +-- + +DROP FUNCTION IF EXISTS public.encode_cp850(text); +CREATE OR REPLACE FUNCTION public.encode_cp850(text) +RETURNS text AS +$BODY$ + SELECT CASE WHEN $1 ~ '[^\x01-\x7F]' THEN utf8_to_cp850($1) ELSE $1 END; +$BODY$ +LANGUAGE sql IMMUTABLE; -- 2.39.5