Last active
January 6, 2022 08:08
-
-
Save tommorris/096f512e32c6b82128e00931f82cddd6 to your computer and use it in GitHub Desktop.
Multi-mode example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ config( | |
materialized="view", | |
schema="marketing") | |
}} | |
with customer_orders as ( | |
select | |
customer_id, | |
min(order_date) as first_order_date, | |
max(order_date) as most_recent_order_date, | |
count(order_id) as number_of_orders | |
from jaffle_shop.orders | |
group by 1 | |
) | |
select | |
customers.customer_id, | |
customers.first_name, | |
customers.last_name, | |
customer_orders.first_order_date, | |
customer_orders.most_recent_order_date, | |
coalesce(customer_orders.number_of_orders, 0) as number_of_orders | |
from jaffle_shop.customers | |
left join customer_orders using (customer_id) | |
-- borrowed from https://docs.getdbt.com/docs/building-a-dbt-project/building-models/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_query = r""" | |
SELECT * FROM puny_humans | |
WHERE vaporised_at IS NULL | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sequel.migration do | |
up do | |
run(<<~SQL) | |
ALTER TABLE puny_humans | |
ADD COLUMN vaporised_at TIMESTAMP | |
SQL | |
end | |
down do | |
run(<<~SQL) | |
ALTER TABLE puny_humans | |
DROP COLUMN vaporised_at | |
SQL | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment