-
I have a I am looping through the array to add to the enum type Here is the relevant code: tags.forEach(async (tag) => {
if (!existingEnums.includes(tag)) {
try {
await sql`
ALTER TYPE tags ADD VALUE ${tag}
`;
} catch (err) {
console.error(`Error adding ${tag}: ${err}`);
}
}
}); This always ends up emitting the following error, for each array item:
When I run the query with What am I doing wrong? And how do I fix it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Some Wiresharking reveals the SQL query Apparently, there are no follow-up packets sending the parameter values. The next packet recorded contains the error message from the Postgres instance. This is weird because |
Beta Was this translation helpful? Give feedback.
-
You can't use protocol level parameters for queries like that. You need to use sql.unsafe, so something like this perhaps await sql`
ALTER TYPE tags ADD VALUE ${ sql.unsafe(`'${ tag.replace(/[^a-z]/g, '') }'`) }
` If you're sure that |
Beta Was this translation helpful? Give feedback.
You can't use protocol level parameters for queries like that. You need to use sql.unsafe, so something like this perhaps
If you're sure that
tag
is properly sanitized and not a way for sql injection to sneak in you can leave out the replace..