golang现在用松鼠更新设置时间

Right now my container's timezone is different with MySQL's, and I need to run a query to just update the time field on MySQL to its timezone. Normally, I can run the query with "edited=NOW()", but with the Golang squirrel, it does not have a proper way to set this clause. I cannot change both my app and mysql container's timezone, and I just need to update the date in DB. Is there any way to do in Squirell properly?

Instead of Set(column, "NOW()"), you need to do Set(column, sq.Expr("NOW()"))

I assume you're using this squirrel package, next time give a link and ideally some example code. So I assume what you really want is sql like this:

update tablename set dt_edited=NOW() where id=1;

You could easily just build that with fmt.Sprintf safely, and execute it with the db driver directly or via sq.Exec().

sql := fmt.Sprintf("update tablename set dt_edited=NOW() where id=%d" tableA.ID)

Using squirrel you probably want something like:

db.Exec(update tablename set dt_edited=NOW() where id=?",tableA.ID)

I'm not sure on the exact syntax but something like that should work fine, you just need a query object to send sql to. Don't attempt to send dt_edited=NOW() as a param as that will get escaped the id you can safely pass in that way.


You’re passing it as a string. Try:

Set("dt_edited=NOW()")