Use age_in_days for age calculations#1119
Merged
labkey-martyp merged 3 commits intorelease26.3-SNAPSHOTfrom Apr 28, 2026
Merged
Use age_in_days for age calculations#1119labkey-martyp merged 3 commits intorelease26.3-SNAPSHOTfrom
labkey-martyp merged 3 commits intorelease26.3-SNAPSHOTfrom
Conversation
labkey-bpatel
approved these changes
Apr 27, 2026
Contributor
labkey-bpatel
left a comment
There was a problem hiding this comment.
Looks good! Please review my comment.
| " CAST(CASE WHEN x.birth IS NULL OR x.effDate IS NULL THEN NULL\n" + | ||
| " ELSE age_in_days(x.birth, x.effDate) END AS INTEGER) AS AgeAtTimeDays,\n" + | ||
| " CAST(CASE WHEN x.birth IS NULL OR x.effDate IS NULL THEN NULL\n" + | ||
| " ELSE CONVERT(age_in_months(x.birth, x.effDate), INTEGER) END AS INTEGER) AS AgeAtTimeMonths,\n" + |
Contributor
There was a problem hiding this comment.
AgeAtTimeYearsRounded, AgeAtTimeDays, and AgeAtTimeMonths - these were previously cast as float (even though it produced whole number values first), but now they are integer -- is this intentional?
Contributor
Author
There was a problem hiding this comment.
reverted these back to float
labkey-martyp
added a commit
to LabKey/platform
that referenced
this pull request
Apr 28, 2026
#### Rationale 1. age_in_days / age(..., SQL_TSI_DAY) — Preserves SQL Server's calendar-boundary semantics for timestampdiff(SQL_TSI_DAY, ...) on Postgres, where the native operator counts 24-hour intervals instead. Consistent with the existing age_in_months/age_in_years functions; permanent addition to LabKey SQL. 2. CAST(... AS BOOLEAN) in SELECT lists (QuerySelect.java) — On SQL Server, boolean QMethodCalls in a select list are wrapped in CASE WHEN (...) THEN 1 ELSE 0 END to avoid predicates as scalar values. But CAST(x AS BIT) is already a value, not a predicate, and SQL Server rejects the wrapped form. Fix excludes ConvertInfo from the wrap. (repro: insert failing query / error) 3. DatabaseMigrationService.registerSchemaContributor — Interface for DatabaseMigrationService.registerSchemaContributor in premiumModules #### Related Pull Requests - LabKey/premiumModules#499 - LabKey/tnprcEHRModules#277 - LabKey/ehrModules#1119 #### Changes - Method.java — age_in_days method, age(..., SQL_TSI_DAY) dispatch, updated validation - QueryTestCase.jsp — tests for both new syntaxes including datetime calendar-boundary cases - LabKeySql.md — documents age_in_days - QuerySelect.java — skip boolean wrap for CAST/CONVERT on SQL Server - DatabaseMigrationService.java — new registerSchemaContributor interface method --------- Co-authored-by: Adam Rauch <adam@labkey.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale
The new age_in_days is consistent across postgres and sql server and more in-line with age as measuring calendar days. A few fixes and cleanups associated with age calculations as well.
Related Pull Requests
Changes