Reputation: 9
I have prepared the query as
await db.runSql(
`PREPARE fetchDashboards (text, text, text) AS SELECT \* FROM dashboards WHERE tenant_id = $1 AND user_id = $2 AND name = $3`,
);
and when I try to execute it
const dashboardResult = await db.runSql(
'EXECUTE fetchDashboards($1, $2, $3)',
[filter.tenant_id, filter.user_id, filter.dashboard_name],
);
I got the following error
Error during migration: error: bind message supplies 1 parameters, but prepared statement "" requires 0 at Parser.parseErrorMessage (/Users/saaifali/JourneyWithSensys/web/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/dist/parser.js:283:98) at Parser.handlePacket (/Users/saaifali/JourneyWithSensys/web/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/dist/parser.js:122:29) at Parser.parse (/Users/saaifali/JourneyWithSensys/web/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/dist/parser.js:35:38) at Socket.<anonymous> (/Users/saaifali/JourneyWithSensys/web/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/dist/index.js:11:42) at Socket.emit (node:events:519:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) at Readable.push (node:internal/streams/readable:390:5) at TCP.onStreamRead (node:internal/stream_base_commons:191:23) { length: 137, severity: 'ERROR', code: '08P01', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'postgres.c', line: '1724', routine: 'exec_bind_message' }
What am I doing wrong? Any help would be highly appreciated
Upvotes: 0
Views: 80
Reputation: 247615
The only statements you can use with parameters are SELECT
, INSERT
, UPDATE
, DELETE
, MERGE
and VALUES
. EXECUTE
is not on that list, hence the error. The EXECUTE
statement has to contain the literal parameter values.
Upvotes: 1