Background
orm:go-pg
Execute whereIn error: Error #42601} syntax} error at} or “near”)
As shown in the figure
The query is as follows:
err = db.Model(&model.Abc{}).WhereIn(“id in (?)”, ids).Column(“id”).Column(“name”).Select(&records)
If IDS is an empty slice, this error will be reported at this time
Solution:
The slices passed in should not be empty. From the business point of view, the length of the list of condition ids to be checked is 0 then the results must not be checked, so you can make a judgment in the outer layer, ids length is 0 then do not take the sql query can be.