Ā© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
11 replies
rphlmr ⚔

[Postgres] prepared with inArray & placeholder

Hello there,

I can't see why It ends with an error :/

export const sumQuery = db
  .select({
    sum: sql<number>`cast(sum(${Table.amount}) as integer)`,
  })
  .from(Table)
  .where(
    inArray(Table.userId, placeholder("userIds"))
  .prepare("sum_query");

// later
const userIds = ['real', 'uuid', 's']
await sumQuery.execute({ userIds });
export const sumQuery = db
  .select({
    sum: sql<number>`cast(sum(${Table.amount}) as integer)`,
  })
  .from(Table)
  .where(
    inArray(Table.userId, placeholder("userIds"))
  .prepare("sum_query");

// later
const userIds = ['real', 'uuid', 's']
await sumQuery.execute({ userIds });


select cast(sum("amount") as integer) from "table" where "table"."user_id" in $1
[
  [
    '54a7291c-7ab5-4ff0-b4a6-612cc5397a57',
    '69312f6a-6eab-4b67-b4d2-be1800f40d73',
    'a80d62dd-b623-42eb-a853-b8caaddd0d1e'
  ]
]
select cast(sum("amount") as integer) from "table" where "table"."user_id" in $1
[
  [
    '54a7291c-7ab5-4ff0-b4a6-612cc5397a57',
    '69312f6a-6eab-4b67-b4d2-be1800f40d73',
    'a80d62dd-b623-42eb-a853-b8caaddd0d1e'
  ]
]


PostgresError: syntax error at or near "$1"
PostgresError: syntax error at or near "$1"


Any idea?
It only fails with array kind placeholder 😢
Looks like
()
()
are missing?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Using a placeholder with an inArray
Drizzle TeamDTDrizzle Team / help
3y ago
prepared statements placeholder typing
Drizzle TeamDTDrizzle Team / help
2y ago
BUG: Prepared statements with placeholder values .execute() not working on postgres
Drizzle TeamDTDrizzle Team / help
3y ago
Cannot use inArray in postgres.
Drizzle TeamDTDrizzle Team / help
14mo ago