dongmu1951 2015-11-06 18:27
浏览 291
已采纳

使用GORM,我是否可以将默认值设置为PostgreSQL函数?

I want something like:

type User struct {
    ID          int     `sql:"default:<myfunction>"`
}

Is this possible with GORM?

  • 写回答

1条回答 默认 最新

  • dongmei5168 2015-11-06 19:07
    关注

    Have you tried it? You can do

    time.Time `sql:"DEFAULT:current_timestamp"`
    

    and it will use the "current_timestamp" function. If you want the default to be the string current_timestamp, you would do

    time.Time `sql:"DEFAULT:'current_timestamp'"`
    

    So, in short, yes, it is possible. You would just do:

    type User struct {
        ID          int     `sql:"DEFAULT:myfunction"`
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?