Passing time.Time value type into WHERE arguments
badsector998 opened this issue · 1 comments
badsector998 commented
I want to simply insert the values into WHERE conditions as follows:
msTable := sq.Select("*").From("sensor_measurements").Where("measured_at >= '?'", startTime).Where("measured_at <= '?'", endTime)
Value type is standard time.Time
and query string after .ToSql()
, the question mark is persist instead generated into complete query string with values intended. Am I missing something?
SELECT * FROM sensor_measurements WHERE measured_at >= '2024-02-01 01:00:00' AND measured_at <= '2024-02-01 02:00:00'
Originally, the complete query intended as follows:
SELECT * FROM sensor_measurements WHERE measured_at BETWEEN '2024-02-01 01:00:00' AND '2024-02-01 02:00:00'
Intended query will be executed into MySQL database using *gorm.DB.Raw()
badsector998 commented
nvm, just remove the single quote and feed the args from ToSQL()
to gorm scan.