Many functions that are classified by GORM as expressions have commas in them. However, as the expression is listed in a string literal in a tag, this terminates the expression.

IE: Field1 string json:"field1" gorm:"uniqueIndex:,expression:NULLIF(field1, '')"

Tries to apply NULLIF(field1, to the index which is obviously meaningless. How do I create this expression?

The only mention of expression in the documentation I could find is this: https://gorm.io/docs/indexes.html#content-inner which has a very limited example that doesn't cover this space.

How to create index expressions with commas in them

Comment From: omris94

Hey @benjfield, We encountered the same issue, you can use \\ to escape the comma. It should look like this: json:"field1" gorm:"uniqueIndex:,expression:NULLIF(field1\\, '')"