Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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