I'm writing a Redshift migration that will be run on a staging DB and a production DB. I want this migration to grant an access to a user, and the name of the user depends on what DB is being migrated.
For example, I want the migration to grant a permission to "staging_user" if the current DB is "staging_db", and to "prod_user" if the current DB is "prod_db".
A naive implementation would look like this :
GRANT SELECT
ON TABLE my_table
TO (SELECT CASE current_database()
WHEN 'staging_db' THEN 'staging_user'
WHEN 'prod_db' THEN 'db_user'
END);
Although, this error tells me SELECT subqueries are not allowed in GRANT statements :
ERROR: syntax error at or near "("
LINE 3: TO (SELECT CASE current_database()
What would be the preferred way of doing this in Redshift?
Edit: I'm running the migrations with Migratus in Clojure, if it can be of any help.