Guest User

Untitled

a guest
Jun 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. DO $$
  2. DECLARE
  3. ALTER_QUERY text;
  4. CURRENT_TABLE_NAME text;
  5. BEGIN
  6. FOR CURRENT_TABLE_NAME IN (
  7. SELECT table_name FROM INFORMATION_SCHEMA.TABLES
  8. WHERE table_schema = 'public'
  9. ) LOOP
  10. FOR ALTER_QUERY IN (
  11. select 'alter table '||table_schema||'.'||table_name||' alter column "'||column_name||'" type text;'
  12. from (
  13. select
  14. table_schema,
  15. table_name,
  16. column_name,
  17. data_type
  18. from INFORMATION_SCHEMA.COLUMNS
  19. where table_name = CURRENT_TABLE_NAME
  20. ) sub
  21. where table_schema = 'public' and (data_type = 'character varying' or data_type = 'character')
  22. ) LOOP
  23. EXECUTE ALTER_QUERY;
  24. END LOOP;
  25. END LOOP;
  26. END;
  27. $$;
Add Comment
Please, Sign In to add comment