Pg: Missing auto quote

Created on 25 Jul 2017  路  2Comments  路  Source: go-pg/pg

Trying to get a user with its associations with a where condition on the user:

    err = db.
        Model(&user).
        Column("user.*", "Company", "PendingOperations").
        Where("id = ?id").
        First()

The problem:

Where("id = ?id")   #=> Fail: ambiguous

```go
Where("user.id = ?id") #=> Fail: Syntax error

```go
Where("\"user\".\"id\" = ?id")   #=> Works but ugly

Any insights on this?

Most helpful comment

user is a keyword in Postgres so you should escape it via Where(`"user".id = ?id`)

All 2 comments

user is a keyword in Postgres so you should escape it via Where(`"user".id = ?id`)

Thank you so much, been having trouble with it for a longtime !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eicca picture eicca  路  3Comments

m-kad picture m-kad  路  3Comments

enchantner picture enchantner  路  3Comments

AbooJan picture AbooJan  路  5Comments

willsr picture willsr  路  5Comments