K
Kysely10mo ago
capaj

Error this query cannot be compiled to SQL

I am trying to do
await trx.executeQuery(
sql<any>`ALTER SCHEMA ${current.subdomain} RENAME TO ${subdomain};`
)
}
await trx.executeQuery(
sql<any>`ALTER SCHEMA ${current.subdomain} RENAME TO ${subdomain};`
)
}
anybody have an idea how to do this query?
Solution:
I the end I went with ``ts await sql .raw(ALTER SCHEMA "${current.subdomain}" RENAME TO "${subdomain}"`) .execute(trx)...
Jump to solution
7 Replies
koskimas
koskimas10mo ago
Subtitutions are by default treated as values and passed as parameters. You want identifiers here. You can use sql.id
await trx.executeQuery(
sql<any>`ALTER SCHEMA ${sql.id(current.subdomain)} RENAME TO ${sql.id(subdomain)};`
)
await trx.executeQuery(
sql<any>`ALTER SCHEMA ${sql.id(current.subdomain)} RENAME TO ${sql.id(subdomain)};`
)
another way is to just run a completely raw query
await trx.executeQuery(
sql.raw(`ALTER SCHEMA ${current.subdomain} RENAME TO ${subdomain};`)
)
await trx.executeQuery(
sql.raw(`ALTER SCHEMA ${current.subdomain} RENAME TO ${subdomain};`)
)
capaj
capaj10mo ago
this still throws
this query cannot be compiled to SQL
this query cannot be compiled to SQL
capaj
capaj10mo ago
also TS is not happy about this
No description
Solution
capaj
capaj10mo ago
I the end I went with
await sql
.raw(`ALTER SCHEMA "${current.subdomain}" RENAME TO "${subdomain}"`)
.execute(trx)
await sql
.raw(`ALTER SCHEMA "${current.subdomain}" RENAME TO "${subdomain}"`)
.execute(trx)
koskimas
koskimas10mo ago
Yeah, I'm not sure executeQuery should even work with raw SQL. Is it even public interface? It is It should probably work
capaj
capaj10mo ago
no worries, DDL queries are quite an edgecase for most query builders
koskimas
koskimas10mo ago
Hmm.. The function takes a CompiledQuery or a Compilable. RawBuilder (returned from sql) shouldn't be either. I'll take a look at this. Something funky here
Want results from more Discord servers?
Add your server