Can anyone help me understand why my code (see below) is resulting in the following error:
Exception in thread “main” java.lang.UnsupportedOperationException:
nth not supported on this type: PersistentStructMap
(defn search [query]
(with-connection db
(with-query-results rs [query]
(doseq [[k v] rs]
(println v)))))
(search (nth *command-line-args* 0))
rsis a sequence (list), representing all the records in your resultset. Each element ofrsis a hashmap representing a single record, with key/value pairs in the map representing field names and values for that record. You’re trying to do the equivalent of this:This is trying to destructure each map into
[k v], doing the rough equivalent of this:If you’re trying to print the value for every field in every record, you need to do this:
“For each record in the resultset, for each key/value in that record, print the value.”
If your resultset contains only a single record (or you only care about one of them) and you’re trying to iterate over the fields of that single record, then pass
doseqonly thefirst:“For every key/value in the first record of the resultset, print the value.”