Pg: Syntax error with db.Insert()

Created on 7 Jul 2018  路  2Comments  路  Source: go-pg/pg

Sintax error when using db.Insert()

db = pg.Connect(&pg.Options{
        User:     "postgres",
        Password: "pass",
        Database: "database",
    })

var n int
_, err := db.QueryOne(pg.Scan(&n), "SELECT 1")
if err != nil {
    panic(err)
}
err := db.Insert(&Word{
    definition: "definition",
})

if err != nil {
    panic(err)
}

Table in the database is called words and the definition of the struct Word is

type Word struct {
    word       string
    language   string
    definition string
    examples   []string
}

Output:
panic: ERROR #42601 syntax error at or near ")" (addr="[::1]:5432")

Most helpful comment

You can look at the generated query via https://github.com/go-pg/pg/wiki/FAQ#how-can-i-viewlog-queries-this-library-generates

All 2 comments

You can look at the generated query via https://github.com/go-pg/pg/wiki/FAQ#how-can-i-viewlog-queries-this-library-generates

@vmihailenco thank you! Thanks to that I realized that fields in struct must be capitalized

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eicca picture eicca  路  3Comments

ValorVl picture ValorVl  路  3Comments

sas1024 picture sas1024  路  5Comments

owentran picture owentran  路  6Comments

willsr picture willsr  路  5Comments