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

DATETIME_DIFF implementation varies between postgres and bigquery #1549

Open
alistairewj opened this issue May 17, 2023 · 0 comments
Open

DATETIME_DIFF implementation varies between postgres and bigquery #1549

alistairewj opened this issue May 17, 2023 · 0 comments

Comments

@alistairewj
Copy link
Member

As raised in #1529, DATETIME_DIFF in PostgreSQL calculates a fractional number, whereas DATETIME_DIFF in BigQuery returns a whole number. This results in a subtle divergence of the concepts in the two dialects. urine_output_rate may be affected as various comparisons expected fractional values to be returned:

-- note that we assume data charted at charttime corresponds
-- to 1 hour of UO, therefore we use '5' and '11' to restrict the
-- period, rather than 6/12 this assumption may overestimate UO rate
-- when documentation is done less than hourly
, SUM(CASE WHEN DATETIME_DIFF(io.charttime, iosum.charttime, HOUR) <= 5
THEN iosum.urineoutput
ELSE null END) AS urineoutput_6hr
, SUM(CASE WHEN DATETIME_DIFF(io.charttime, iosum.charttime, HOUR) <= 5
THEN iosum.tm_since_last_uo
ELSE null END) / 60.0 AS uo_tm_6hr

Easiest fix is to (1) update postgres-functions.sql and (2) update the UO query to take a similar approach to the kdigo_uo query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant