Skip to content

Use TIMESTAMP_TRUNC instead of DATETIME_TRUNC for BigQuery #1765

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

courtneyholcomb
Copy link
Contributor

@courtneyholcomb courtneyholcomb commented May 28, 2025

A user flagged that the DATETIME_TRUNC operation was causing a query to not use their BQ date partition properly, resulting in more GB of data processed than expected.
After doing some research, it looks like the DATETIME_TRUNC also converts a timestamp object to a datetime object, which removes any timezone info. We don't intend to ever change the timezone of the underlying column, so this is not what we want.
The downside of this change is that, for any BQ users who are using timezone-aware data that's not UTC, they might see a change in the output. This is because DATETIME_TRUNC converts to UTC by default before truncating. Regardless, most users using BigQuery should be using UTC as best practice.

This PR updates the BQ SQL renderer to use TIMESTAMP_TRUNC instead of DATETIME_TRUNC.

@dbt-labs dbt-labs deleted a comment from github-actions bot May 28, 2025
@dbt-labs dbt-labs deleted a comment from github-actions bot May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants