sql.placeholder not working for pg array of strings

const create = db
.insert(eventTable)
.values({
title: sql.placeholder('title'),
images: sql.placeholder('images')
})
.returning()
.prepare('createEvent');
const create = db
.insert(eventTable)
.values({
title: sql.placeholder('title'),
images: sql.placeholder('images')
})
.returning()
.prepare('createEvent');
export const eventTable = pgTable('event', {
id: uuid('id').primaryKey().defaultRandom(),
title: text('title').notNull(),
images: text('images').array(),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow()
});
export const eventTable = pgTable('event', {
id: uuid('id').primaryKey().defaultRandom(),
title: text('title').notNull(),
images: text('images').array(),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow()
});
This fails at start time (not even until calling the DB, right after starting the server) with the following error:
TypeError: value.map is not a function
at PgArray.mapToDriverValue (file:///project/node_modules/drizzle-orm/pg-core/columns/common.js:93:21)
at file:///project/node_modules/drizzle-orm/sql/sql.js:119:73
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:91:21
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:94:21
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:52:26
at Object.startActiveSpan (file:///project/node_modules/drizzle-orm/tracing.js:8:14)
at SQL.toQuery (file:///project/node_modules/drizzle-orm/sql/sql.js:51:19)
at PgDialect.sqlToQuery (file:///project/node_modules/drizzle-orm/pg-core/dialect.js:362:17)
at file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:124:53
at Object.startActiveSpan (file:///project/node_modules/drizzle-orm/tracing.js:8:14)
at QueryPromise._prepare (file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:123:19)
at QueryPromise.prepare (file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:128:17)
at /project/src/server/db/models/event.ts:17:4
at async instantiateModule (file:///project/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:50861:9)
TypeError: value.map is not a function
at PgArray.mapToDriverValue (file:///project/node_modules/drizzle-orm/pg-core/columns/common.js:93:21)
at file:///project/node_modules/drizzle-orm/sql/sql.js:119:73
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:91:21
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:94:21
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:52:26
at Object.startActiveSpan (file:///project/node_modules/drizzle-orm/tracing.js:8:14)
at SQL.toQuery (file:///project/node_modules/drizzle-orm/sql/sql.js:51:19)
at PgDialect.sqlToQuery (file:///project/node_modules/drizzle-orm/pg-core/dialect.js:362:17)
at file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:124:53
at Object.startActiveSpan (file:///project/node_modules/drizzle-orm/tracing.js:8:14)
at QueryPromise._prepare (file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:123:19)
at QueryPromise.prepare (file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:128:17)
at /project/src/server/db/models/event.ts:17:4
at async instantiateModule (file:///project/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:50861:9)
4 Replies
Angelelz
Angelelz10mo ago
You can't use placeholder for arrays
Angelelz
Angelelz10mo ago
GitHub
[BUG]: inArray in prepared statements causes syntax error with Plan...
What version of drizzle-orm are you using? 0.28.6 What version of drizzle-kit are you using? 0.19.13 Describe the Bug When using inArray in a prepared statement in Planetscale it throws a syntax er...
Angelelz
Angelelz10mo ago
Check that comment I made in an issue in GH. Somebody offered a solution, I haven tested it but it's worth a try
CrisOG
CrisOGOP10mo ago
Thank you! @Angelelz
Want results from more Discord servers?
Add your server