Skip to content

Instantly share code, notes, and snippets.

@alexanderdean
Last active December 23, 2015 12:29
Show Gist options
  • Save alexanderdean/6636086 to your computer and use it in GitHub Desktop.
Save alexanderdean/6636086 to your computer and use it in GitHub Desktop.
-- Quick workaround script because Redshift view definitions are tied to
-- table IDs, not table names. Means if a table is swapped out for a new
-- one, the views will all point to the old table.
-- To use this:
-- 1. Change your viewowner to whoever created your views
-- 2. Change your table names (if necessary)
-- 3. Run the script against your database
-- 4. Paste the output into your SQL client and execute
-- WARNINGS:
-- Please make sure all of the viewowner's views are BACKED UP before running
-- Please DO NOT RUN this against any kind of system/super user
SELECT 'DROP VIEW "' + schemaname + '"."' + viewname + '" CASCADE; ' +
REPLACE('CREATE VIEW "' + schemaname + '"."' + viewname + '" as ' + definition,
'FROM events_old',
'FROM events')
FROM pg_views WHERE viewowner = 'admin';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment