gpt4 book ai didi

postgresql - 如何在 GORM 中将 PostgreSQL 函数设置为默认值?

转载 作者:IT王子 更新时间:2023-10-29 00:52:25 27 4
gpt4 key购买 nike

我想要这样的东西:

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

GORM 可以吗?

最佳答案

你试过了吗?你可以做

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

它将使用“current_timestamp”函数。如果您希望默认值为字符串 current_timestamp,您可以这样做

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

所以,简而言之,是的,这是可能的。你只需要做:

type User struct {
ID int `sql:"DEFAULT:myfunction"`
}

关于postgresql - 如何在 GORM 中将 PostgreSQL 函数设置为默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33573306/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com