How would I create a Postgresql index with NULLS NOT DISTINCT option in gorm?
Tried it with gorm:"index:,option:NULLS NOT DISTINCT", but it didn't work.
See this if you need more context: https://stackoverflow.com/questions/8289100/create-unique-constraint-with-null-columns
Comment From: a631807682
currently not supported
Comment From: philip-madden
Any plans to implement this?
Comment From: Ponywka
Just use pointers to make this fields nullable ~~at least it works in my case~~
type SomethingThird struct {
ID int64
SomethingFirstID *int64 `gorm:"index:,unique"`
SomethingSecondID *int64 `gorm:"index:,unique"`
}
Comment From: wandering-tales
Just use pointers to make this fields nullable ~at least it works in my case~
go type SomethingThird struct { ID int64 SomethingFirstID *int64 `gorm:"index:,unique"` SomethingSecondID *int64 `gorm:"index:,unique"` }
Did work or not?
Comment From: nikolai-momot-thirdfort
go index:,unique
It does not work when I tested it locally
Comment From: abbyssoul
Thank you for raising this issue; I, too, have run into this exact problem.
Here is PR to enable the use of the option param for PG indexes: https://github.com/go-gorm/postgres/pull/288
Note, if I understand the code correctly, the index will only be created if it doesn't exist. So, there is no migration for existing indexes. Thus, when the above PR is merged, it should be possible to specify option:NULLS NOT DISTINCT, but for it to take effect for an existing table, you'll need to delete the existing index first and run a migration.