mauricio / postgresql-async

Async, Netty based, database drivers for PostgreSQL and MySQL written in Scala
Apache License 2.0
1.43k stars 222 forks source link

prepared statement not working when in operator in statement with conjunction with Seq[String] #228

Open shachr opened 7 years ago

shachr commented 7 years ago

prepared statement not working when in operator in statement with conjunction with Seq[String],

code:

def getDemand(advertizerId: String, demandIds: Seq[String]): Future[Array[QueryResult]] = {
    val args = List(advertizerId, value)
    val query: String = s"""SELECT "demand_id"
                      |from demand where "partner_id"=? and "demand_id" in (?);""".stripMargin
    connection.sendPreparedStatement(query, args)
}

demand_id is a string field (character varying(32))

pg sql logs:

2017-08-01 16:23:35 IDT LOG:  execute 1/1: SELECT "demand_id" from demand where "partner_id"=$1 and "demand_id" in ($2);
2017-08-01 16:23:35 IDT DETAIL:  parameters: $1 = 'ea47ef7e8b4c4847894004198e7b9e56', $2 = '{"565f776a61db4ccdab36946116699622"}'

I couldn't figure out what todo, i tried to serialize to comma separated list myself but this didn't work as well, directly on the db its working obviously.

thanks.

liorhar commented 7 years ago

bumped into the same problem, SELECT * FROM bar WHERE column IN (?) with a parameter in the form of list/seq doesn't work. any workaround?

liorhar commented 7 years ago

found a workaround (at least for postgre) one can write SELECT * from bar WHERE column = ANY(?) then pass an array or list. It should have the same results (see here)