字段顺序查询MySQL从Clojure JDBC [英] Field order on query MySQL from Clojure JDBC

查看:192
本文介绍了字段顺序查询MySQL从Clojure JDBC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从Clojure(jdbc)查询MySQL时,字段不按SELECT子句中指定的顺序返回(我调用执行选择的存储过程)。最初,似乎字段以相反的顺序返回,但这只会发生在1到9个字段。添加第十个字段使得结果集没有特定的顺序,尽管对于结果集中的特定数量的字段总是相同的顺序。

When I query MySQL from Clojure (jdbc), the fields are not returned in the order specified in SELECT clause (I'm calling a stored procedure that does the select). Initially it seemed that the fields were returned in the reverse order, but this happens only if there are 1 to 9 fields. Adding the tenth field makes the result set to go in no particular order, altough it is always the same order for a particular number of fields in result set.

任何人都观察到它?

推荐答案

您可以询问 java.jdbc 通过传递:as-arrays来返回单独的行作为向量而不是地图(或者数组,尽管选项名称)。 true 查询;字段顺序将被保留:

You can ask java.jdbc to return individual rows as vectors rather than maps (or arrays, in spite of the option name) by passing :as-arrays? true to query; field order will then be preserved:

;; checked with java.jdbc 0.3.0-alpha4
(query db [sql params...] :as-arrays? true)

请注意,在这种操作模式中,包含对应于列名称(否则将在构造的映射中使用)的键的额外向量将被添加到实际结果向量的seq。

Note that in this mode of operation an extra vector containing the keys corresponding to the column names (which would otherwise be used in the constructed maps) will be prepended to the seq of actual result vectors.

默认情况下,java.jdbc按照Arthur的回答,以地图形式返回行。这些将是最多9个条目(维护插入顺序)和哈希映射超过此阈值(没有有用的排序)的数组映射。

By default, java.jdbc returns rows as maps, as per Arthur's answer. These will be array maps up to 9 entries (maintaining insertion order) and hash maps beyond this threshold (with no useful ordering).

这篇关于字段顺序查询MySQL从Clojure JDBC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆