Last active
December 30, 2015 22:58
-
-
Save LeoBenoist/7897300 to your computer and use it in GitHub Desktop.
This is a patch to fix special char (accents...) bugs (bad charset, encoding) for PostgreSQL in PgSQL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO $$ | |
DECLARE | |
tables CURSOR FOR (SELECT TABLE_NAME as "name", COLUMN_NAME as "column" FROM INFORMATION_SCHEMA.COLUMNS WHERE (DATA_TYPE LIKE '%char%' OR DATA_TYPE = 'text') AND TABLE_SCHEMA = 'public'); | |
BEGIN | |
FOR table_record IN tables LOOP | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''é'',''é'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''ä'',''ä'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''ö'',''ö'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''Ã¥'',''å'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''è'',''è'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''Ç'',''ç'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''é'',''é'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''ů'',''ů'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''ü'',''ü'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''ß'',''ß'')'; | |
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''Ã…'',''Å'')'; | |
END LOOP; | |
END$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment