-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[5.2] change whereDate method for Postgres #12341
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
Conversation
Can you post the query that was causing problems so I can reproduce it? |
@taylorotwell Sounds like it's not a "bug", just a refactor. |
Here it is
|
Don't call |
It still doesn't work. |
? |
Not entirely sure. |
I think one problem with this is people are going to pass a full Carbon object into this and expect the time to be respected. Whereas this ::date operator is going to cut-off the hours, minutes, and seconds. |
[5.2] change whereDate method for Postgres
…lumns (#55159) In #12341, the cast to `::date` was added to `whereDate`. This leads to an error with PostgreSQL when passing in json column selectors. For example: `->whereDate('result->created_at', DB::raw('NOW()'))` will throw a syntax error for type date. The same is true for the `whereTime` function with its `::time` cast. To fix this, we need to wrap the column identifier in parentheses, when they are json paths. Current SQL output: ```SQL select * from "users" where "result"->>'created_at'::date = NOW() ``` Correct SQL output with this commit: ```SQL select * from "users" where ("result"->>'created_at')::date = NOW() ```
…lumns (#55159) In laravel/framework#12341, the cast to `::date` was added to `whereDate`. This leads to an error with PostgreSQL when passing in json column selectors. For example: `->whereDate('result->created_at', DB::raw('NOW()'))` will throw a syntax error for type date. The same is true for the `whereTime` function with its `::time` cast. To fix this, we need to wrap the column identifier in parentheses, when they are json paths. Current SQL output: ```SQL select * from "users" where "result"->>'created_at'::date = NOW() ``` Correct SQL output with this commit: ```SQL select * from "users" where ("result"->>'created_at')::date = NOW() ```
I just had a problem with no results for a query using this method.
Wouldn't it be better to cast the column instead of the value ?