From 2f24d70363f4bbb68a46ae3ff9ba9d80d185ffde Mon Sep 17 00:00:00 2001 From: Kyle Huston Date: Tue, 14 Oct 2025 13:56:02 -0400 Subject: [PATCH] Quote grantees when granting or revoking for Redshift --- .../include/redshift/macros/apply_grants.sql | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 dbt-redshift/src/dbt/include/redshift/macros/apply_grants.sql diff --git a/dbt-redshift/src/dbt/include/redshift/macros/apply_grants.sql b/dbt-redshift/src/dbt/include/redshift/macros/apply_grants.sql new file mode 100644 index 000000000..0ef252a56 --- /dev/null +++ b/dbt-redshift/src/dbt/include/redshift/macros/apply_grants.sql @@ -0,0 +1,22 @@ +{%- macro quote_grantees(grantees) -%} + {%- set quoted_grantees = [] -%} + {%- for grantee in grantees -%} + {%- set grantee_parts = grantee.split() -%} + {%- if grantee_parts | length > 1 and grantee_parts[0].upper() in ('GROUP', 'ROLE') -%} + {%- set reserved_keyword = grantee_parts[0].upper() -%} + {%- set identifier = grantee_parts[1:] | join(' ') -%} + {%- do quoted_grantees.append(reserved_keyword ~ ' ' ~ adapter.quote(identifier)) -%} + {%- else -%} + {%- do quoted_grantees.append(adapter.quote(grantee)) -%} + {%- endif -%} + {% endfor -%} + {%- do return(quoted_grantees) -%} +{%- endmacro -%} + +{%- macro redshift__get_revoke_sql(relation, privilege, grantees) -%} + revoke {{ privilege }} on {{ relation.type }} {{ relation }} from {{ quote_grantees(grantees) | join(', ') }} +{%- endmacro -%} + +{%- macro redshift__get_grant_sql(relation, privilege, grantees) -%} + grant {{ privilege }} on {{ relation.type }} {{ relation }} to {{ quote_grantees(grantees) | join(', ') }} +{%- endmacro -%}