]> git.8kb.co.uk Git - postgresql/encoding_woes/blobdiff - codepage_850.sql
Added sql functions to check if we really need to do any conversion.
[postgresql/encoding_woes] / codepage_850.sql
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;