thejonyboybr
thejonyboybr
Explore posts from servers
DTDrizzle Team
Created by thejonyboybr on 6/5/2023 in #help
BUG: Prepared statements with placeholder values .execute() not working on postgres
I'm trying to execute a prepared statement with placeholder() values
export const articlePreparedQueryNodePg = dbNodePg
.select()
.from(article)
.where(
sql`(${placeholder("author")} IS NULL OR ${
article.authorName
} = ${placeholder("author")})`
)
.limit(placeholder("limit"))
.offset(placeholder("offset"))
.prepare("article_prepared");
export const articlePreparedQueryNodePg = dbNodePg
.select()
.from(article)
.where(
sql`(${placeholder("author")} IS NULL OR ${
article.authorName
} = ${placeholder("author")})`
)
.limit(placeholder("limit"))
.offset(placeholder("offset"))
.prepare("article_prepared");
but when I do execute it
const articlesWithAuthor = await articlePreparedQueryNodePg.execute({
author: "John Doe",
limit: 10,
offset: 0,
});

//or
const allArticles = await articlePreparedQueryNodePg.execute({
author: null,
limit: 10,
offset: 0,
});
const articlesWithAuthor = await articlePreparedQueryNodePg.execute({
author: "John Doe",
limit: 10,
offset: 0,
});

//or
const allArticles = await articlePreparedQueryNodePg.execute({
author: null,
limit: 10,
offset: 0,
});
This error is thrown:
error: 'could not determine data type of
parameter $1'
error: 'could not determine data type of
parameter $1'
Is anyone having this issue in other db dialects? I opened an issue: https://github.com/drizzle-team/drizzle-orm/issues/709 Minimal repo to reproduce this: https://github.com/greidinger-reis/drizzle-prepared-stmt-null-bug-node-pg
1 replies