java.jdbc

How to preserve order of rows?

Details

  • Type: Enhancement Enhancement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • 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?

Activity

Hide
Sean Corfield added a comment -

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').

Show
Sean Corfield added a comment - 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').
Hide
Konstantin added a comment -

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?

Show
Konstantin added a comment - 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?
Hide
Sean Corfield added a comment -

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)))

Show
Sean Corfield added a comment - 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)))
Hide
Sean Corfield added a comment -

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.

Show
Sean Corfield added a comment - 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.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: