java.jdbc

Don't make column names unique when `as-arrays?` is true

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

result-set-seq ensures that column name keys are unique by suffixing identical column names with an incrementing integer. This is important and required when returning maps as key collisions are possible (result sets can easily contain multiple columns with same label, in different positions) and would yield surprising results.

However, when result-set-seq is called with :as-arrays? true, rows are returned as vectors with the columns ordered as in the SQL query. The first row returned is a vector of column names. In the current implementation, column name keys are still made unique.

I find this behaviour unhelpful as it introduces an unnecessary difference between column names as returned by the query and what they are called in the column name row.

I propose the following change:

When as-arrays? is true, don't make column names unique. This is obviously breaking change if you rely on the uniquified column names (unlikely?). If this is considered a too big risk, I propose we introduce an option to toggle this behaviour uniquify-column-names?, defaulting to true.

Activity

Hide
Ragnar Dahlen added a comment -

Attached initial go at a patch, taking the less conservative approach and changing the current behaviour.

Show
Ragnar Dahlen added a comment - Attached initial go at a patch, taking the less conservative approach and changing the current behaviour.
Hide
Sean Corfield added a comment - - edited

I'd want to survey some of the java.jdbc users who rely on as-arrays? before changing the default behavior but I can see the value in suppressing the uniqueness behavior.

Show
Sean Corfield added a comment - - edited I'd want to survey some of the java.jdbc users who rely on as-arrays? before changing the default behavior but I can see the value in suppressing the uniqueness behavior.
Hide
Sean Corfield added a comment -

I think the approach I'm going to take here is to allow :as-arrays? to be either true, false, or :cols-as-is. So :as-arrays? true will continue to work as it does now but if you specify :as-arrays? :cols-as-is it will work like :as-arrays? true but also omit the step that makes column names unique.

Show
Sean Corfield added a comment - I think the approach I'm going to take here is to allow :as-arrays? to be either true, false, or :cols-as-is. So :as-arrays? true will continue to work as it does now but if you specify :as-arrays? :cols-as-is it will work like :as-arrays? true but also omit the step that makes column names unique.
Hide
Sean Corfield added a comment -

:as-arrays? can now be true, false, or :cols-as-is. The default remains false. Specifying :cols-as-is behaves like true but also suppresses the column uniqueness logic.

Show
Sean Corfield added a comment - :as-arrays? can now be true, false, or :cols-as-is. The default remains false. Specifying :cols-as-is behaves like true but also suppresses the column uniqueness logic.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: