<< Back to previous view

[JDBC-41] How to preserve order of rows? Created: 24/Dec/12  Updated: 07/Apr/13  Resolved: 07/Apr/13

Status: Resolved
Project: java.jdbc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Konstantin Assignee: Sean Corfield
Resolution: Completed Votes: 0
Labels: None


 Description   

I'd like to get the ordered record set within with-query-results
(or the way to restore the original order).
Is this possible with clojure/java.jdbc?



 Comments   
Comment by Sean Corfield [ 24/Dec/12 12:49 PM ]

I assume you mean the order of columns within the rows, not the actual order of rows within the result set?

I'm looking at providing an alternative result set format using arrays instead of maps which will preserve column orders.

Since maps are unordered by default in Clojure, I'd be suspicious of code that relies on ordering of keys (so I'm reducing this to 'minor').

Comment by Konstantin [ 24/Dec/12 10:54 PM ]

You are right, I mean the order of columns, not the rows.

I understand, that maps are unordered. There are few reasons when
the order is matters. The one of them is my task - simple
SQL database client.

Probably it would be better to do this possibility optional,
since it is not used very often?

Comment by Sean Corfield [ 25/Dec/12 8:26 PM ]

An optional keyword argument sounds like a reasonable compromise. I'm already looking at keyword arguments on resultset-seq for returning arrays instead of maps and returning an order-preserving map should be as simple as replacing (zipmap keys (row-values)) with (apply array-map (interleave keys (row-values)))

Comment by Sean Corfield [ 07/Apr/13 3:38 AM ]

Fixed in 0.3.0-SNAPSHOT by allowing :as-arrays argument to query and result-set-seq functions, which returns result as vector of column names, followed by vectors for each row.

Generated at Sat Oct 25 04:48:07 CDT 2014 using JIRA 4.4#649-r158309.