This file contains 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
-- Rename tables | |
DO $$ | |
DECLARE | |
table_record RECORD; | |
BEGIN | |
-- Loop through each table | |
FOR table_record IN (SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE') LOOP | |
EXECUTE FORMAT('ALTER TABLE public.%I RENAME TO %I', table_record.table_name, lower(regexp_replace(table_record.table_name, '(.)([A-Z])', '\1_\2', 'g'))); | |
END LOOP; | |
END $$; |