Я получаю эту ошибку nodejs, когда пытаюсь выполнить свой запрос с параметрами ($ 1, $ 2, $ 3).Запрос работает в postgres.Это также работает, если я не использую параметры ($ 1, $ 2, $ 3) и заменяю их значениями.Может ли кто-нибудь помочь мне определить проблему?
error: bind message supplies 3 parameters, but prepared statement "" requires 0
Запрос, который я пытаюсь выполнить:
var theQuery = `DO
$do$
BEGIN
IF EXISTS (SELECT * FROM commentsvoted WHERE id = $1 AND user_id = $2) THEN
with t as (
SELECT votes FROM commentsvoted WHERE commentsvoted.id = $1 AND
commentsvoted.user_id = $2
),
cv as (
UPDATE commentsvoted
SET votes = (CASE WHEN t.votes THEN NULL ELSE true END)
FROM t
WHERE commentsvoted.id = $1 AND commentsvoted.user_id = $2
)
UPDATE comments
SET upvoted = (CASE WHEN t.votes THEN upvoted - 1
WHEN t.votes IS NULL THEN upvoted + 1
ELSE upvoted
END),
downvoted = (CASE WHEN NOT t.votes THEN downvoted - 1
ELSE downvoted
END)
FROM t
WHERE comment_id = $1 AND posted_by = $2;
ELSE
with t as (UPDATE comments SET upvoted = upvoted + 1
WHERE comment_id = $1 AND posted_by = $2)
INSERT INTO commentsvoted(id, user_id, votes, thread_id)
VALUES($1, $2, true, $3);
END IF;
END
$do$`;
client.query(theQuery, [commentId, userId, threadId])