Skip to content

Instantly share code, notes, and snippets.

@tommorris
Last active January 6, 2022 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommorris/096f512e32c6b82128e00931f82cddd6 to your computer and use it in GitHub Desktop.
Save tommorris/096f512e32c6b82128e00931f82cddd6 to your computer and use it in GitHub Desktop.
Multi-mode example
{{ 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/
my_query = r"""
SELECT * FROM puny_humans
WHERE vaporised_at IS NULL
"""
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