Skip to content

Commit

Permalink
Escape % symbols in table/view/column comments (#466) (#471)
Browse files Browse the repository at this point in the history
* Use tests with table/view/column-level comments

* Changelog entry

* escape % until the underlying issue is fixed in redshift_connector

* Revert "Use tests with table/view/column-level comments"

This reverts commit 1b41d8c.

(cherry picked from commit adb4482)

Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and dbeatty10 authored May 25, 2023
1 parent 5fa30ae commit 3e19923
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230524-151825.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Escape `%` symbols in table/view/column comments
time: 2023-05-24T15:18:25.834088-06:00
custom:
Author: dbeatty10
Issue: "441"
18 changes: 18 additions & 0 deletions dbt/include/redshift/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,21 @@
{% endif %}

{% endmacro %}

{#
By using dollar-quoting like this, users can embed anything they want into their comments
(including nested dollar-quoting), as long as they do not use this exact dollar-quoting
label. It would be nice to just pick a new one but eventually you do have to give up.
#}
{% macro postgres_escape_comment(comment) -%}
{% if comment is not string %}
{% do exceptions.raise_compiler_error('cannot escape a non-string: ' ~ comment) %}
{% endif %}
{%- set magic = '$dbt_comment_literal_block$' -%}
{%- if magic in comment -%}
{%- do exceptions.raise_compiler_error('The string ' ~ magic ~ ' is not allowed in comments.') -%}
{%- endif -%}
{#- -- escape % until the underlying issue is fixed in redshift_connector -#}
{%- set comment = comment|replace("%", "%%") -%}
{{ magic }}{{ comment }}{{ magic }}
{%- endmacro %}

0 comments on commit 3e19923

Please sign in to comment.