-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
[bugfix] Fix case sensitivity of date column for postgres #5962
[bugfix] Fix case sensitivity of date column for postgres #5962
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5962 +/- ##
=======================================
Coverage 63.56% 63.56%
=======================================
Files 393 393
Lines 23667 23667
Branches 2638 2638
=======================================
Hits 15044 15044
Misses 8610 8610
Partials 13 13
Continue to review full report at Codecov.
|
@mistercrunch could it be possible to get a review and/or maybe get this merged? :) |
I am concerned that this PR will again revive #3844. From the issues and PRs within this very issue you can see that this topic is very controversial. That time we came to these conclusions:
|
@rumbin good point, I didn't know the And indeed a workaround is to exploit that situation to make a calculated column with a proper name. Isn't the actual real solution to the problem to stop trying to manipulate SQL by hand and use the proper tools so that this situation does not arise? According to @villebro, using sqlalchemy to generate those queries would be "not too readable" (cf #5886 (comment)) but at least it would be correct in all cases, right? I will close this for now, but I would really appreciate if you, @rumbin, could chip in the discussion in #5886 so that we find a solution to this situation? |
Same here: as we haven't used calculated time columns, this problem didn't come to mind. Thanks for chiming in @rumbin . @victornoel: Luckily time grains can be modified locally by adding the following in your TIME_GRAIN_ADDON_FUNCTIONS = {
'postgres': {
None: '"{col}"',
'PT1S': "DATE_TRUNC('second', \"{col}\") AT TIME ZONE 'UTC'",
'PT1M': "DATE_TRUNC('minute', \"{col}\") AT TIME ZONE 'UTC'",
'PT1H': "DATE_TRUNC('hour', \"{col}\") AT TIME ZONE 'UTC'",
'P1D': "DATE_TRUNC('day', \"{col}\") AT TIME ZONE 'UTC'",
'P1W': "DATE_TRUNC('week', \"{col}\") AT TIME ZONE 'UTC'",
'P1M': "DATE_TRUNC('month', \"{col}\") AT TIME ZONE 'UTC'",
'P0.25Y': "DATE_TRUNC('quarter', \"{col}\") AT TIME ZONE 'UTC'",
'P1Y': "DATE_TRUNC('year', \"{col}\") AT TIME ZONE 'UTC'",
}
} This will replace the built-in time grains with the ones defined above. Perhaps this is the best solution for now. |
In case anyone else comes across the workaround posted by @villebro keep in mind that the database name recognized by SQLAlchemy seems to be e.g. TIME_GRAIN_ADDON_FUNCTIONS = {
'postgresql': {
None: '"{col}"',
'PT1S': "DATE_TRUNC('second', \"{col}\") AT TIME ZONE 'UTC'",
'PT1M': "DATE_TRUNC('minute', \"{col}\") AT TIME ZONE 'UTC'",
'PT1H': "DATE_TRUNC('hour', \"{col}\") AT TIME ZONE 'UTC'",
'P1D': "DATE_TRUNC('day', \"{col}\") AT TIME ZONE 'UTC'",
'P1W': "DATE_TRUNC('week', \"{col}\") AT TIME ZONE 'UTC'",
'P1M': "DATE_TRUNC('month', \"{col}\") AT TIME ZONE 'UTC'",
'P0.25Y': "DATE_TRUNC('quarter', \"{col}\") AT TIME ZONE 'UTC'",
'P1Y': "DATE_TRUNC('year', \"{col}\") AT TIME ZONE 'UTC'",
}
} |
Closes #5886
After discussing with @villebro in #5886, we arrived to the conclusion that we shouldn't fix this bug globally by using sqlalchemy to generate the query but only at the level of postgresql.
The rationale is to avoid impacting other db since it seems this may only be touching postgres.