From: glyn Date: Wed, 12 Mar 2014 12:36:52 +0000 (+0000) Subject: Added sql functions to check if we really need to do any conversion. X-Git-Url: https://git.8kb.co.uk/?a=commitdiff_plain;h=HEAD;p=postgresql%2Fencoding_woes Added sql functions to check if we really need to do any conversion. --- 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;