I am trying to pivot a column with an apostrophe but this is very difficult in DBT. Any ideas? I tried double quotes but dbt does not pick this up, and I cannot use a like statement in a pivot.
{% set pvt_details=[
('General liability cover_rated_premium' , 'gl_premium')
, ('Contractors' errors and omissions cover_rated_premium','eo_premium') ] %}
WITH filtered AS (
SELECT
quote_id
, target
, premium_after_amount
from {{ source('acdc', 'chopin_quote_rating_steps') }} cqrs
WHERE target IN ({% for column in pvt_details %} '{{column[0]}}' {%- if not loop.last -%}
, {%- endif %}
{% endfor %})
AND action = 'initial_premium'
)
select *
from filtered
pivot(sum(premium_after_amount)
for target in ({% for column in pvt_details %} '{{column[0]}}' {%- if not loop.last -%} ,
{%- endif %}
{% endfor %}))
as p (quote_id,
{% for column in pvt_details %} {{column[1]}} {%- if not loop.last -%} , {%- endif
%}
{% endfor %})