I am using PostgreSQL 9.4 and the cool JSONB field type. I am trying to request a field in a document. In psql CLI works
SELECT id FROM program WHERE document -> 'dept' ? 'CS'
When I try to run the same request through my Scala application, I get the error message below. I use Play framework and Anorm, so the request looks like this:
SQL(s"SELECT id FROM program WHERE document -> 'dept' ? {dept}") .on('dept -> "CS") ....
SQLException :: No value specified for parameter 5. (SimpleParameterList.java:223)
(there are more options in my real queries)
I can get around this by setting my parameter for jsonb input and using the @> operator to check for containment.
SQL(s"SELECT id FROM program WHERE document -> 'dept' @> {dept}::jsonb") .on('dept -> "CS") ....
I'm not too keen on work. I do not know if there are penalties for execution, but this is an extra input and unobvious.
Is there anything else I can do?
postgresql jdbc anorm jsonb
Jason
source share