title: Is it possible to retrieve a column value by name using GoLang database/sql
body: <p>All of the examples I've seen for using <code>sql.Row</code>, access return values from queries by <strong>position</strong>:<code>sql.Rows.scan()</code> requires a correctly typed variable correctly <strong>positioned</strong> in the <code>scan()</code> arguments corresponding to the appropriate column, to retrieve each column value returned, such as in the following example: </p>
  
  <p><a href="http://golang.org/pkg/database/sql/#pkg-examples" rel="noreferrer"><strong>Example Based on GoDocs (with small mod):</strong></a></p>
  
  <pre><code>rows, err := db.Query("SELECT name,age FROM users WHERE age&gt;=50")
  if err != nil {
      log.Fatal(err)
  }
  for rows.Next() {
      var name string
      var age int
  
      if err := rows.Scan(&amp;name,&amp;age); err != nil {
          log.Fatal(err)
      }
      fmt.Printf("%s is %d\n", name, age)
  }
  if err := rows.Err(); err != nil {
      log.Fatal(err)
  } 
  </code></pre>
  
  <p><code>&amp;name</code> and <code>&amp;age</code> must be positioned correctly (columns 0 and 1) for Rows.Scan() to retrieve the correct values with the correct types.</p>
  
  <p>Over my years of development for production systems, I have come to studiously avoid this practice because it's not robust: A database change in the layout of the columns will easily break your code if it's based on column positions. </p>
  
  <p>It is far more robust to use <strong>column names</strong> for retrieving values - this insulates you from changes to the database that add or remove columns that screw up your position based code. For example, in Delphi and C#, all dataSets, including columns returning values from queries, support <code>FieldByName('age').asInteger</code> or <code>fields['age'].value,</code> etc. </p>
  
  <p>Any way to accomplish this in Go? If not, this is a big drawback in Go database support and a serious disappointment - not at all safe, as mentioned.</p>
  
  <p><em><strong>Edit:</em></strong></p>
  
  <p>Also <em>(perhaps this is a new question)</em>: The examples I've seen seem to require you to retrieve all the columns returned by the query, or the positions of the columns will be skewed. </p>
  
  <p>Suppose there is  utility query in a locked-down database that I cannot modify or add to, and it retrieves several columns, but I only need one of them for my current task. Based on the current <code>sql.Rows.Scan()</code> model, I have to retrieve all the values from the query in my application code, even though I don't need them, whereas if I could query <code>"columnByName"</code> that would not be necessary - I could just bring into my application code the data I need. Any work-around for this?</p>