ARTICLE AD BOX
I'm trying to execute a prepared statement with two placeholders.
The query is the following:
CREATE SCHEMA IF NOT EXISTS $1 AUTHORIZATION $2;However, the following error is returned by the DELVE debugger.
pq: syntax error at or near "$1"The following is my GO source code:
package main import ( "fmt" "log" "database/sql" _ "github.com/lib/pq" ) type CreateSchemaQueryStruct struct { SchemaName string OwnerRoleName string } func main() { var dataSourceName string = fmt.Sprintf( "%s://%s:%s@%s:%d/%s?sslmode=disable", "postgres", "username", "password", "localhost", 5432, "tabularium") db, err := sql.Open("postgres", dataSourceName) if err != nil { log.Fatal(err) } defer db.Close() err = db.Ping() if err != nil { log.Fatal(err) } var createSchemaQueryContents string = "CREATE SCHEMA IF NOT EXISTS $1 AUTHORIZATION $2;" var createSchemaQueryStruct CreateSchemaQueryStruct = CreateSchemaQueryStruct{"Meta", "thesevs"} stmt, err := db.Prepare(string(createSchemaQueryContents)) if err != nil { log.Fatal(err) } defer stmt.Close() _, err = stmt.Exec( createSchemaQueryStruct.SchemaName, createSchemaQueryStruct.OwnerRoleName) if err != nil { log.Fatal(err) } }I checked the query directly on psql and it works.
What am I missing?
