]> git.8kb.co.uk Git - postgresql/encoding_woes/commitdiff
Added sql functions to check if we really need to do any conversion. master
authorglyn <glyn@8kb.co.uk>
Wed, 12 Mar 2014 12:36:52 +0000 (12:36 +0000)
committerglyn <glyn@8kb.co.uk>
Wed, 12 Mar 2014 12:36:52 +0000 (12:36 +0000)
codepage_850.sql [new file with mode: 0644]

diff --git a/codepage_850.sql b/codepage_850.sql
new file mode 100644 (file)
index 0000000..4661a59
--- /dev/null
@@ -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;