Search code examples
postgresqlgopq

golang/pq pq: operator does not exist: bigint = text


query := "WITH b(ColA, ColB) AS (VALUES ($1,$2)) UPDATE schema_name.table_name AS a SET ColC = b.ColB FROM b WHERE a.ColA = b.ColA AND a.ColB = b.ColB"
res, err := db.Exec(query, 1, 1)

The above code fails with the following error:

pq: operator does not exist: bigint = text

"ColC" is of type BIGINT.

From my investigation, the driver is inserting the values as text instead of ints.

issue: https://github.com/lib/pq/issues/582


Solution

  • It turns out to be the postgres behavior and not the driver. I had to use explicit casts to get my queries to work.