You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The call is essentially equivalent to db.build("SELECT $1::int[]").exec([1, 2]), so QueryMethods#exec builds a statement and forwards args to Statement#exec.
The reason for this fails is that Statement#exec(*args) is shadowed by #exec(args : Array) which can be used to pass a dynamic array of param bindings instead of varargs.
When the only query param is an array, this is interpreted as an array of params, instead of an array as single param.
A workaround is to wrap the array in another array: db.exec("SELECT $1::int[]", [[1, 2]]) which will effectively call #exec(args : Array) with a params array including the intended array as single value.
While the workaround is relatively simple, this behaviour is very unexpected. Every other type works fine as a param provided as vararg. Array should just work as well.
A solution would be to make args : Array a required named argument: #exec(*, args : Array). Thus, when calling exec([1, 2]), it passes the array [1, 2] as single param. When calling exec(args: [1, 2]), it passes two params, 1 and 2. The delegating methods need to get support for this named argument as well.
(The prepared statement being empty in the error message is another issue).
The text was updated successfully, but these errors were encountered:
The following query fails (using pg driver):
Error message:
The call is essentially equivalent to
db.build("SELECT $1::int[]").exec([1, 2])
, soQueryMethods#exec
builds a statement and forwardsargs
toStatement#exec
.The reason for this fails is that
Statement#exec(*args)
is shadowed by#exec(args : Array)
which can be used to pass a dynamic array of param bindings instead of varargs.When the only query param is an array, this is interpreted as an array of params, instead of an array as single param.
A workaround is to wrap the array in another array:
db.exec("SELECT $1::int[]", [[1, 2]])
which will effectively call#exec(args : Array)
with a params array including the intended array as single value.While the workaround is relatively simple, this behaviour is very unexpected. Every other type works fine as a param provided as vararg. Array should just work as well.
A solution would be to make
args : Array
a required named argument:#exec(*, args : Array)
. Thus, when callingexec([1, 2])
, it passes the array[1, 2]
as single param. When callingexec(args: [1, 2])
, it passes two params,1
and2
. The delegating methods need to get support for this named argument as well.(The prepared statement being empty in the error message is another issue).
The text was updated successfully, but these errors were encountered: