Tag Archives: db&orm

[Solved] ERROR #42601 syntax error at or near “)“

 

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.

Solve the problem of postgre error #22p02 malformed array literal

catalogue

Background

Problem solving


Background

When you use the go PG framework to modify a column, an error occurs.

The column to be modified is bigint [] type. Keep trying, and multiple errors are reported as follows:

Missing   “=”   after   array   dimensions

ERROR #22P02 malformed array literal

Problem solving

Modify data directly:

update table_name set  xxx= '{1,2}' where id=2;

  This modification is successful. Is it right to contact the code and convert the value types to be injected?Yes, that’s it!

Code mode: set (“column =?”, Val)   

Convert each value of Val of type [] Int64 into a string, and concatenate the string with commas: ` {% s}`

Expand to see: set (“column =?”, ` {1,2} ‘)   

Done!