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

MySQL functions in where statement #47

Closed
jgrusewski opened this issue Oct 22, 2014 · 2 comments
Closed

MySQL functions in where statement #47

jgrusewski opened this issue Oct 22, 2014 · 2 comments

Comments

@jgrusewski
Copy link

Currently I'm facing the following issue.
I would like to do some date/time comparison queries like:
SELECT * FROM mytable WHERE DATE(mydate) = DATE(NOW())

Q: SELECT * FROM mytable WHERE (DATE(mydate) = ?) LIMIT 1000
A: [0000]
E: "Error 1054: Unknown column 'DATE(shipping_date)' in 'where clause'"
T: 0.00039s

What is the best way to approach this issue?

@xiam
Copy link
Member

xiam commented Oct 23, 2014

You can use the db.Raw type to pass conditions that you would not like to treat as arguments and should be passed without any kind of filtering:

col.Find(db.Raw{`DATE(mydate) = DATE(NOW())`})

@jgrusewski
Copy link
Author

Thanks for your quick reply

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

2 participants