Skip to content

Commit

Permalink
Fix/get column values (dbt-labs#154)
Browse files Browse the repository at this point in the history
* Fix incorrect get_column_values usage

* Improve usage docs for unpivot

* Improve get_column_values usage docs
  • Loading branch information
Claire Carroll authored Jul 29, 2019
1 parent c8991e6 commit f3ec633
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ models:
---
### SQL helpers
#### get_column_values ([source](macros/sql/get_column_values.sql))
This macro returns the unique values for a column in a given table.
It takes an options `default` argument for compiling when relation does not already exist.
This macro returns the unique values for a column in a given [relation](https://docs.getdbt.com/docs/api-variable#section-relation).
It takes an options `default` argument for compiling when the relation does not already exist.

Usage:
```
Expand Down Expand Up @@ -300,7 +300,7 @@ Usage:

Example:

Input: public.test
Input: orders

| size | color |
|------|-------|
Expand All @@ -311,9 +311,11 @@ Example:

select
size,
{{ dbt_utils.pivot('color', dbt_utils.get_column_values('public.test',
'color')) }}
from public.test
{{ dbt_utils.pivot(
'color',
dbt_utils.get_column_values(ref('orders'), 'color')
) }}
from {{ ref('orders') }}
group by size

Output:
Expand Down Expand Up @@ -341,7 +343,14 @@ This macro "un-pivots" a table from wide format to long format. Functionality is

Usage:
```
{{ dbt_utils.unpivot(table=ref('table_name'), cast_to='datatype', exclude=[<list of columns to exclude from unpivot>], remove=[<list of columns to remove>], field_name=<column name for field>, value_name=<column name for value>) }}
{{ dbt_utils.unpivot(
table=ref('table_name'),
cast_to='datatype',
exclude=[<list of columns to exclude from unpivot>],
remove=[<list of columns to remove>],
field_name=<column name for field>,
value_name=<column name for value>
) }}
```

Example:
Expand Down

0 comments on commit f3ec633

Please sign in to comment.