How would you write this REPLACE query?

UPDATE Examples
SET prompt = REPLACE(prompt, 'textToReplaceFrom', 'textToReplaceWith')
WHERE id IN [array of ids];
UPDATE Examples
SET prompt = REPLACE(prompt, 'textToReplaceFrom', 'textToReplaceWith')
WHERE id IN [array of ids];
I'm trying something like this:
await db.execute(
sql`UPDATE ${examplesTable} SET prompt = REPLACE(${
examplesTable.prompt
}, ${replaceTextFrom}, ${replaceTextTo}) WHERE ${
examplesTable.id
} IN (${selected.included})`
await db.execute(
sql`UPDATE ${examplesTable} SET prompt = REPLACE(${
examplesTable.prompt
}, ${replaceTextFrom}, ${replaceTextTo}) WHERE ${
examplesTable.id
} IN (${selected.included})`
but am getting this error: NeonDbError: db error: ERROR: argument of WHERE must be type boolean, not type record I don't really understand why the where is not type boolean here because I'm using an IN statement.
1 Reply
rphlmr ⚡
rphlmr ⚡17mo ago
Maybe
await db.execute(
sql`UPDATE ${examplesTable} SET prompt = REPLACE(${
examplesTable.prompt
}, ${replaceTextFrom}, ${replaceTextTo}) WHERE ${inArray(examplesTable.id, selected.included)}`
await db.execute(
sql`UPDATE ${examplesTable} SET prompt = REPLACE(${
examplesTable.prompt
}, ${replaceTextFrom}, ${replaceTextTo}) WHERE ${inArray(examplesTable.id, selected.included)}`
Using drizzle inArray helper
Want results from more Discord servers?
Add your server