Борьба с выполнением запроса, в котором для одного условия требуется приведение varchar в виде десятичного числа в между оператором.
Запрос выполняется через построитель запросов Knex.
Пример:
...//code
csdbCount = await queries.baseQuery('p.personId', ['07'], 7, 'Asian')
.andWhereBetween(queries.knex.raw('CAST(dosd.value as decimal(11,3))'), [20.00, 30.00]);
После запуска я получаю сообщение об ошибке
RequestError: Error converting data type varchar to numeric.
at handleError (node_modules/mssql/lib/tedious.js:566:15)
at Parser.tokenStreamParser.on.token (node_modules/tedious/lib/connection.js:716:12)
at Parser.parser.on.token (node_modules/tedious/lib/token/token-stream-parser.js:27:14)
at addChunk (node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:297:12)
at readableAddChunk (node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:279:11)
at Parser.Readable.push (node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:240:10)
at Parser.Transform.push (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:139:32)
at doneParsing (node_modules/tedious/lib/token/stream-parser.js:80:14)
at token (node_modules/tedious/lib/token/infoerror-token-parser.js:48:5)
at call.lineNumber (node_modules/tedious/lib/token/infoerror-token-parser.js:13:19)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:179:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readUInt32LE (node_modules/tedious/lib/token/stream-parser.js:176:10)
at parser.readBVarChar.procName (node_modules/tedious/lib/token/infoerror-token-parser.js:12:90)
at readBuffer.data (node_modules/tedious/lib/token/stream-parser.js:316:9)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:308:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readBuffer (node_modules/tedious/lib/token/stream-parser.js:305:10)
at readUInt8.length (node_modules/tedious/lib/token/stream-parser.js:315:12)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:123:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readUInt8 (node_modules/tedious/lib/token/stream-parser.js:120:10)
at Parser.readBVarChar (node_modules/tedious/lib/token/stream-parser.js:314:10)
at parser.readBVarChar.serverName (node_modules/tedious/lib/token/infoerror-token-parser.js:11:22)
at readBuffer.data (node_modules/tedious/lib/token/stream-parser.js:316:9)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:308:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readBuffer (node_modules/tedious/lib/token/stream-parser.js:305:10)
at readUInt8.length (node_modules/tedious/lib/token/stream-parser.js:315:12)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:123:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readUInt8 (node_modules/tedious/lib/token/stream-parser.js:120:10)
at Parser.readBVarChar (node_modules/tedious/lib/token/stream-parser.js:314:10)
at parser.readUsVarChar.message (node_modules/tedious/lib/token/infoerror-token-parser.js:10:20)
at readBuffer.data (node_modules/tedious/lib/token/stream-parser.js:325:9)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:308:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readBuffer (node_modules/tedious/lib/token/stream-parser.js:305:10)
at readUInt16LE.length (node_modules/tedious/lib/token/stream-parser.js:324:12)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:147:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readUInt16LE (node_modules/tedious/lib/token/stream-parser.js:144:10)
at Parser.readUsVarChar (node_modules/tedious/lib/token/stream-parser.js:323:10)
at parser.readUInt8.clazz (node_modules/tedious/lib/token/infoerror-token-parser.js:9:18)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:123:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readUInt8 (node_modules/tedious/lib/token/stream-parser.js:120:10)
at parser.readUInt8.state (node_modules/tedious/lib/token/infoerror-token-parser.js:8:16)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:123:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readUInt8 (node_modules/tedious/lib/token/stream-parser.js:120:10)
at parser.readUInt32LE.number (node_modules/tedious/lib/token/infoerror-token-parser.js:7:14)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:179:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readUInt32LE (node_modules/tedious/lib/token/stream-parser.js:176:10)
at parser.readUInt16LE (node_modules/tedious/lib/token/infoerror-token-parser.js:6:12)
at awaitData (node_modules/tedious/lib/token/stream-parser.js:147:7)
at Parser.awaitData (node_modules/tedious/lib/token/stream-parser.js:103:7)
at Parser.readUInt16LE (node_modules/tedious/lib/token/stream-parser.js:144:10)
at parseToken (node_modules/tedious/lib/token/infoerror-token-parser.js:5:10)
at Object.errorParser (node_modules/tedious/lib/token/infoerror-token-parser.js:45:3)
at Parser.parseTokens (node_modules/tedious/lib/token/stream-parser.js:89:27)
at Parser._transform (node_modules/tedious/lib/token/stream-parser.js:66:12)
at Parser.Transform._read (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:177:10)
at Parser.Transform._write (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:164:83)
at doWrite (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:405:139)
at writeOrBuffer (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:394:5)
at Parser.Writable.write (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:303:11)
at Parser.addBuffer (node_modules/tedious/lib/token/token-stream-parser.js:37:24)
at Connection.sendDataToTokenStreamParser (node_modules/tedious/lib/connection.js:1265:35)
at Connection.data (node_modules/tedious/lib/connection.js:2081:26)
at Connection.dispatchEvent (node_modules/tedious/lib/connection.js:1084:36)
at MessageIO.messageIo.on.data (node_modules/tedious/lib/connection.js:981:14)
at Message.message.on.chunk (node_modules/tedious/lib/message-io.js:29:14)
at addChunk (node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:297:12)
at readableAddChunk (node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:279:11)
at Message.Readable.push (node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:240:10)
at Message.Transform.push (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:139:32)
at Message.afterTransform (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:88:10)
at Message.PassThrough._transform (node_modules/tedious/node_modules/readable-stream/lib/_stream_passthrough.js:38:3)
at Message.Transform._read (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:177:10)
at Message.Transform._write (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:164:83)
at doWrite (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:405:139)
at writeOrBuffer (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:394:5)
at Message.Writable.write (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:303:11)
at Message.Writable.end (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:559:51)
at IncomingMessageStream.processBufferedData (node_modules/tedious/lib/incoming-message-stream.js:58:19)
at IncomingMessageStream._transform (node_modules/tedious/lib/incoming-message-stream.js:83:10)
at IncomingMessageStream.Transform._read (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:177:10)
at IncomingMessageStream.Transform._write (node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:164:83)
at doWrite (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:405:139)
at writeOrBuffer (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:394:5)
at IncomingMessageStream.Writable.write (node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:303:11)
at Socket.ondata (_stream_readable.js:667:20)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
Выполнение этого запроса в DataGrip работает отлично, что еще больше удивляет меня после выполнения через Knex.Что можно изменить, чтобы преодолеть это?Заранее спасибо.