What am i doing wrong here? Tried quoting new_name also , still shows error : pq: syntax error at or near "$1" Postgres + go
func ChangeDBname(new_name string) {
oldname := "intern"
quoted := pq.QuoteIdentifier(oldname)
_, e1 := db.Exec(fmt.Sprintf("ALTER TABLE %s RENAME TO $1",quoted) , new_name)
if e1 != nil {
fmt.Println("Eroor in change name")
log.Fatal(e1.Error())
} else {
fmt.Println("Table name changed to", new_name)
}
}
Table name is not a value. So PostgreSQL parser is not expecting a placeholder in this DDL.
Check this:
db.Exec(fmt.Sprintf("ALTER TABLE %s RENAME TO %s",pq.QuoteIdentifier(oldname), pq.QuoteIdentifier(new_name)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With