Skip to content

Commit

Permalink
Merge pull request #135 from ArtifactUprising/feature/pivot-quote-par…
Browse files Browse the repository at this point in the history
…ameter

Added quote_identifiers argument
  • Loading branch information
drewbanin authored May 13, 2019
2 parents 4c2eb2c + 3ff0008 commit 1b983ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ Arguments:
- suffix: Column alias postfix, default is blank
- then_value: Value to use if comparison succeeds, default is 1
- else_value: Value to use if comparison fails, default is 0
- quote_identifiers: Whether to surround column aliases with double quotes, default is true

#### unpivot ([source](macros/sql/unpivot.sql))
This macro "un-pivots" a table from wide format to long format. Functionality is similar to pandas [melt](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.melt.html) function.
Expand Down
10 changes: 8 additions & 2 deletions macros/sql/pivot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Arguments:
suffix: Column alias postfix, default is blank
then_value: Value to use if comparison succeeds, default is 1
else_value: Value to use if comparison fails, default is 0
quote_identifiers: Whether to surround column aliases with double quotes, default is true
#}

{% macro pivot(column,
Expand All @@ -46,7 +47,8 @@ Arguments:
prefix='',
suffix='',
then_value=1,
else_value=0) %}
else_value=0,
quote_identifiers=True) %}
{% for v in values %}
{{ agg }}(
case
Expand All @@ -56,7 +58,11 @@ Arguments:
end
)
{% if alias %}
as {{ adapter.quote(prefix ~ v ~ suffix) }}
{% if quote_identifiers %}
as {{ adapter.quote(prefix ~ v ~ suffix) }}
{% else %}
as {{prefix ~ v ~ suffix }}
{% endif %}
{% endif %}
{% if not loop.last %},{% endif %}
{% endfor %}
Expand Down

0 comments on commit 1b983ed

Please sign in to comment.