Skip to content

Reestablish warning on duplicate column in query. #1825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

schauder
Copy link
Contributor

Closes #1680

Object rsv = JdbcUtils.getResultSetValue(resultSet, i + 1);
String columnName = md.getColumnLabel(i + 1);
document.put(columnName, rsv instanceof Array a ? a.getArray() : rsv);
Object old = document.put(columnName, rsv instanceof Array a ? a.getArray() : rsv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we're not using putIfAbsent semantics. Obtaining a value from the ResultSet typically uses the first occurrence of a column while we should be agnostic to the fact whether a column occurs multiple times in the result.

For reference, none of Spring JDBC's mappers care about duplicate columns, they just accept the fact that ResultSet either returns different values when iterating over the column count or use the value by name lookup.

Furthermore, when an external query declares the same column names, why is it us to validate this concern?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the JDBC spec says when you have duplicate column names, the first one should be returned.

Copy link
Contributor Author

@schauder schauder Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it us to validate this concern?

Because we are nice people and we notice something is weird.

@@ -66,9 +71,13 @@ static RowDocument toRowDocument(ResultSet resultSet) throws SQLException {
RowDocument document = new RowDocument(columnCount);

for (int i = 0; i < columnCount; i++) {

Object rsv = JdbcUtils.getResultSetValue(resultSet, i + 1);
String columnName = md.getColumnLabel(i + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We should use JdbcUtils.lookupColumnName(…) here.

schauder added a commit that referenced this pull request Jul 1, 2024
schauder added a commit that referenced this pull request Jul 1, 2024
Also, fallback on column names when label is not present.

See #1680
Original pull request #1825
schauder added a commit that referenced this pull request Jul 1, 2024
schauder added a commit that referenced this pull request Jul 1, 2024
Also, fallback on column names when label is not present.

See #1680
Original pull request #1825
schauder added a commit that referenced this pull request Jul 1, 2024
schauder added a commit that referenced this pull request Jul 1, 2024
Also, fallback on column names when label is not present.

See #1680
Original pull request #1825
@schauder
Copy link
Contributor Author

schauder commented Jul 1, 2024

Made the changes requested by the review and merged.

@schauder schauder closed this Jul 1, 2024
@schauder schauder added this to the 3.2.8 (2023.1.8) milestone Jul 1, 2024
@schauder schauder deleted the issue/1680-duplicate-column branch July 18, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug encountered with duplicate column names in result set, but only in specific alias order
2 participants