title: Dynamic get query in go using pgx
body: <p>So I found this: <a href="https://betterprogramming.pub/dynamic-sql-query-with-go-8aeedaa02907" rel="nofollow noreferrer">https://betterprogramming.pub/dynamic-sql-query-with-go-8aeedaa02907</a></p>
  <p>it explains how to create a dynamic query for the basic sql package. I would like to do the same thing in pgx but i cant get it to work. Here is my code:</p>
  <pre><code>func (db *Database) Query(query string, queryParams ...interface{}) {
  
      rows, _ := db.conn.Query(context.Background(), query)
      defer rows.Close()
  
      fieldDescriptions := rows.FieldDescriptions()
  
      var cols []string
      for _, fieldDesc := range fieldDescriptions {
          cols = append(cols, string(fieldDesc.Name))
      }
  
      row := make([][]byte, len(cols))
      rowPtr := make([]interface{}, len(cols))
      for i := range row {
          rowPtr[i] = &amp;row[i]
      }
  
      for rows.Next() {
          err := rows.Scan(rowPtr...)
          if err != nil {
              fmt.Println(err.Error())
          }
  
          fmt.Println(rowPtr)
      }
  }
  </code></pre>
  <p>With this I get an error:</p>
  <pre><code>can't scan into dest[0]: cannot assign 1 into *[]uint8
  </code></pre>
  <p>The first item in the row is an id, the first has 1, so its trying to put the int into a *[]uint8, no idea whats going on there.</p>
  <p>If i take out row stuff the</p>
  <pre><code>row := make([][]byte, len(cols))
  
  for i := range row {
      rowPtr[i] = &amp;row[i]
  }
  </code></pre>
  <p>and just try to read directly to a variadic array of interface{} I would have thought it would read into it, since the Scan takes an interface{}, but i just get nil for everything. Anyone able to shed any light on any of this?</p>