Go中我的模型是:
type Sales_Daily_db struct {
Nation_shipping string
Date datatypes.Date
Impressions int `gorm:"type:integer;"`
Clicks int `gorm:"type:integer;"`
Cost float32
ATB float32
OKL float32
}
当使用上面的模型运行AutoMigrate()
时,我希望pSQL数据库中的impressions
和clicks
列的类型为integer
。然而,即使使用了这些gorm
标签,它们最终仍然是类型int4
。我已经用上面的标签手动尝试了int2 int4 int8
,它们都相应地工作了。此外,当我尝试int
标签时,它们会被强制进入int8
。如何修复这种行为并在pSQL中指定integer
类型?
编辑:我正在使用DBeaver查看数据库。
根据PostgreSQL文档,这是:
SQL only specifies the integer types integer (or int), smallint, and bigint.
The type names int2, int4, and int8 are extensions, which are also used by some other SQL database systems.
您应该可以使用int
、integer
、smallint
和bigint
。除此之外的任何东西都只是别名。