Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the example for get_where_subquery #3689

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented Jul 7, 2023

Preview

What are you changing in this pull request and why?

See Option 2 listed in dbt-labs/dbt-core#8047

🎩

image

Checklist

@netlify
Copy link

netlify bot commented Jul 7, 2023

Deploy Preview for docs-getdbt-com ready!

Name Link
🔨 Latest commit 463f0f5
🔍 Latest deploy log https://app.netlify.com/sites/docs-getdbt-com/deploys/64a75beab668fb0008dea9c6
😎 Deploy Preview https://deploy-preview-3689--docs-getdbt-com.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added content Improvements or additions to content size: small This change will take 1 to 2 days to address labels Jul 7, 2023
@dbeatty10 dbeatty10 marked this pull request as ready for review July 7, 2023 00:50
@dbeatty10 dbeatty10 requested a review from a team as a code owner July 7, 2023 00:50
Copy link
Contributor

@mirnawong1 mirnawong1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm @dbeatty10 !

{% macro get_where_subquery(relation) -%}
    {% set where = config.get('where') %}
    {% if where %}
        {% if "__three_days_ago__" in where %}
            {# replace placeholder string with result of custom macro #}
            {% set three_days_ago = dbt.dateadd('day', -3, current_timestamp()) %}
            {% set where = where | replace("__three_days_ago__", three_days_ago) %}
        {% endif %}
        {%- set filtered -%}
            (select * from {{ relation }} where {{ where }}) dbt_subquery
        {%- endset -%}
        {% do return(filtered) %}
    {%- else -%}
        {% do return(relation) %}
    {%- endif -%}
{%- endmacro %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Improvements or additions to content size: small This change will take 1 to 2 days to address
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants