0

Can someone please explain me what is the difference between using

$1

query, err := b.Db.Prepare("SELECT id, name, owner, coordinates, reason_froggy FROM Business WHERE name ilike $1")
    if err != nil {
        return business_list, err
    }
    rows, err := query.Query("%" + business + "%")
    if err != nil {
        return business_list, err
    }

and

?

query, err := b.Db.Prepare("SELECT id, name, owner, coordinates, reason_froggy FROM Business WHERE name ilike ?")
    if err != nil {
        return business_list, err
    }
    rows, err := query.Query("%" + business + "%")
    if err != nil {
        return business_list, err
    }

are they're supposed to work the same way as an anon param, or they're different?

Also the other thing is that with the $1 param the query runs perfect, but with the ? param the query returns a pg error in syntax.

Luis Cardoza Bird
  • 1,265
  • 4
  • 24
  • 43
  • 1
    `$1` style notation is useful if you want to send a parameter value once, but use it say in multiple places in a single query. – colm.anseo Sep 22 '19 at 03:23
  • 2
    Executive summary: PostgreSQL uses numbered placeholders (`$1`, `$2`, ...) natively and the low level Go interfaces use the database's native placeholders. – mu is too short Sep 22 '19 at 03:42

0 Answers0