Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DO $$
- DECLARE
- ALTER_QUERY text;
- CURRENT_TABLE_NAME text;
- BEGIN
- FOR CURRENT_TABLE_NAME IN (
- SELECT table_name FROM INFORMATION_SCHEMA.TABLES
- WHERE table_schema = 'public'
- ) LOOP
- FOR ALTER_QUERY IN (
- select 'alter table '||table_schema||'.'||table_name||' alter column "'||column_name||'" type text;'
- from (
- select
- table_schema,
- table_name,
- column_name,
- data_type
- from INFORMATION_SCHEMA.COLUMNS
- where table_name = CURRENT_TABLE_NAME
- ) sub
- where table_schema = 'public' and (data_type = 'character varying' or data_type = 'character')
- ) LOOP
- EXECUTE ALTER_QUERY;
- END LOOP;
- END LOOP;
- END;
- $$;
Add Comment
Please, Sign In to add comment