Skip to content

Instantly share code, notes, and snippets.

@cristianc-ty
Created February 8, 2018 13:14
Show Gist options
  • Save cristianc-ty/6c9a85c7467511bafdfbc1de2e0f62d9 to your computer and use it in GitHub Desktop.
Save cristianc-ty/6c9a85c7467511bafdfbc1de2e0f62d9 to your computer and use it in GitHub Desktop.
quick_customer_search_view.sql
-- build a view to show all data that combines
create view quick_customer_search as
select customer_search.*
from customer_search
-- * records that are not marked as stale
where customer_search.is_stale = false
union all
select r.*
from customer_search
-- * records that are stale => recompute the most up to date fields on the fly
cross join refresh_customer_search (customer_search.customer_id, customer_search.contact_id) r
where customer_search.is_stale = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment