Your Question

I have one instance of Postgres DB, and several instances of my app running simultaneously. It is possible they will unsynchronized in time with each other. It will lead to some problems with my business logic because I need to precisely track changes.

I see a possible solution in using now() instead of the exact time 2022-02-09 17:39:47.785 in database transactions, but I don't know how to do it with gorm. Of course, I can update it later with a separate transaction, or even write a raw SQL query and send it via gorm, but it will add unwanted complexity to my code.

So, by doing this

type Data struct {
    gorm.Model
    Value string
}
...
db.Create(&Data{Value: "some value"})

I see this

INSERT INTO "data" ("created_at","updated_at","deleted_at","value") VALUES ('2022-02-09 18:22:44.728','2022-02-09 18:22:44.728',NULL,'some value') RETURNING "id";

And I want to see that

INSERT INTO "data" ("created_at","updated_at","deleted_at","value") VALUES (now(),now(),NULL,'some value') RETURNING "id";

The document you expected this should be explained

https://gorm.io/docs/gorm_config.html

Expected answer

Some code example or a link to the document.

Comment From: jinzhu

by default, not possible. but you could make it works if creating with sql expression, refer: https://gorm.io/docs/create.html#Create-From-SQL-Expression-Context-Valuer, or set a default tag with database specific funcs like now() for those fields