在Golang上随机反向输出sqlx

时间:2018-03-03 09:47:09

标签: go sqlx

使用此代码在Golang中使用sqlx:

rows, err := db.Queryx(`SELECT "SIGN_ID","SIGN_NAME" FROM sign`)
 for rows.Next() {
    results := make(map[string]interface{})
    err = rows.MapScan(results) 
    fmt.Printf("%#v\n", results)
}

结果看起来很有希望:

map[string]interface {}{"SIGN_ID":"JD", "SIGN_NAME":"John Doe"}
map[string]interface {}{"SIGN_ID":"JAD", "SIGN_NAME":"Jane Doe"}
map[string]interface {}{"SIGN_ID":"DD", "SIGN_NAME":"Donald Duck"}
map[string]interface {}{"SIGN_NAME":"Chris Walker", "SIGN_ID":"CW"} <----
map[string]interface {}{"SIGN_ID":"SN", "SIGN_NAME":"St Nicolas"}

两个问题:

  1. 为什么一行随机&#34;反向&#34;输出顺序&lt; ----:
  2.   

    map [string] interface {} {&#34; SIGN_NAME&#34;:&#34; Chris Walker&#34;,&#34; SIGN_ID&#34;:&#34; CW&#34;}

    1. 如何摆脱前缀: map [string] interface {}

1 个答案:

答案 0 :(得分:1)

  1. It is known behaviour。在golang地图中随机排列密钥。
  2. 使用fmt.Printf("%v\n", results)