gocraft/dbr

Postgre JSONB ? operator

ashtonian opened this issue · 5 comments

trying to use the JSONB? operator for a JSON contains function and I'm getting a dbr: wrong placeholder count error. Is there a way to escape the ? ?

Repro:

package main

import "github.com/gocraft/dbr"
import _ "github.com/lib/pq"

func main() {
	const q = `SELECT 1 WHERE '{"test":true}'::JSONB ? ?`
	conn, err := dbr.Open("postgres", "", nil)
	if err != nil {
		panic(err)
	}

	sess := conn.NewSession(nil)

	_, err = sess.SelectBySql(q, "test").Load(nil)
	if err != nil {
		panic(err)
	}
}

is there any solutions?
I have same problem, when my string has ?
it fails at file interpolate.go:
if strings.Count(query, placeholder) != len(value) {

I have the same issue as well, but when trying to insert a dynamic JSONB parsed in a struct

It seems like we need to have a way to express ? literal. In go formatter, we use %% to express % literal, it seems like ?? should be fine. (This is not yet implemented.)

This is also an issue for us

This should be open since bbb1206 inserts the doubled placeholder on the final query, causing a pq driver bug. I patched it on #141 though.