postgres
postgres copied to clipboard
`insert into table as alias` not work with dynamic inserts
Hello.
This is the reproduction code:
const postgres = require('postgres')
const sql = postgres()
main()
async function main() {
await sql`CREATE TABLE IF NOT EXISTS my_users (id serial, name text)`
await sql`INSERT INTO my_users AS u (name) VALUES('name')` // work, with alias
await sql`INSERT INTO my_users ${sql({name: 'name'})}` // work, with dynamic inserts
await sql`INSERT INTO my_users AS u ${sql({name: 'name'})}` // not work, with both alias and dynamic inserts
// error: PostgresError: syntax error at or near "$1"
}
version information:
PostgreSQL: 15
postgres: 3.3.1
Thanks a lot. I think that's gonna be one for v4 when adding more explicit helper methods.