Skip to content

Commit 1b983ed

Browse files
authored
Merge pull request #135 from ArtifactUprising/feature/pivot-quote-parameter
Added quote_identifiers argument
2 parents 4c2eb2c + 3ff0008 commit 1b983ed

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ Arguments:
330330
- suffix: Column alias postfix, default is blank
331331
- then_value: Value to use if comparison succeeds, default is 1
332332
- else_value: Value to use if comparison fails, default is 0
333+
- quote_identifiers: Whether to surround column aliases with double quotes, default is true
333334

334335
#### unpivot ([source](macros/sql/unpivot.sql))
335336
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.

macros/sql/pivot.sql

+8-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Arguments:
3636
suffix: Column alias postfix, default is blank
3737
then_value: Value to use if comparison succeeds, default is 1
3838
else_value: Value to use if comparison fails, default is 0
39+
quote_identifiers: Whether to surround column aliases with double quotes, default is true
3940
#}
4041

4142
{% macro pivot(column,
@@ -46,7 +47,8 @@ Arguments:
4647
prefix='',
4748
suffix='',
4849
then_value=1,
49-
else_value=0) %}
50+
else_value=0,
51+
quote_identifiers=True) %}
5052
{% for v in values %}
5153
{{ agg }}(
5254
case
@@ -56,7 +58,11 @@ Arguments:
5658
end
5759
)
5860
{% if alias %}
59-
as {{ adapter.quote(prefix ~ v ~ suffix) }}
61+
{% if quote_identifiers %}
62+
as {{ adapter.quote(prefix ~ v ~ suffix) }}
63+
{% else %}
64+
as {{prefix ~ v ~ suffix }}
65+
{% endif %}
6066
{% endif %}
6167
{% if not loop.last %},{% endif %}
6268
{% endfor %}

0 commit comments

Comments
 (0)