How to alter database with drizzle (sql magic operator)?

Hi everyone, I am trying to use the sql magic operator to alter a postgres database, but no luck yet. Here's what I am trying to do:
await db.execute(
sql`ALTER DATABASE ${databaseName} SET pg_trgm.similarity_threshold = 0.2;`
);
await db.execute(
sql`ALTER DATABASE ${databaseName} SET pg_trgm.similarity_threshold = 0.2;`
);
However, I am getting PostgresError: syntax error at or near "$1", looks like this operator does not support to use variables when using ALTER DATABASE. Any solution on how to actually perform this operation? It is only running on script (CI/CD), it is not exposed to the public, so security here isn't a huge concern. Thank you!
1 Reply
nelsonprsousa
nelsonprsousaOP10mo ago
Just found what I should use: ${sql.raw(databaseName)} If it helps someone ☝️
Want results from more Discord servers?
Add your server