Skip to content

Duplicate column names #658

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
ForbesLindesay opened this issue Nov 22, 2013 · 11 comments
Closed

Duplicate column names #658

ForbesLindesay opened this issue Nov 22, 2013 · 11 comments

Comments

@ForbesLindesay
Copy link

If a query returns duplicate column names, it is impossible to get all the values out of a record. It would be useful to have a property of the record that allowed you to access the raw list of field values as an array.

@danpetitt
Copy link

I would have thought that would be bad practice anyway as you should use aliases in your SQL for those situations.

@ForbesLindesay
Copy link
Author

Possibly, but I just had someone else write a query that did this and it caused a strange bug in my app. Another alternative would be to throw some kind of error?

The use case that is getting the right headers on a report, something like:

key section 1 value 1 value 2 section 2 value 1 value 2
foo Section Header 1 20 Section Header 5 3
bar Section Header 3 25 Section Header 6 1

@sidorares
Copy link
Member

@felixge
Copy link
Collaborator

felixge commented Nov 25, 2013

Yes, the link provided by @sidorares should explain the solution for this problem.

@felixge felixge closed this as completed Nov 25, 2013
@ForbesLindesay
Copy link
Author

That only works when the columns come from different tables. It doesn't work when all the fields are calculated columns from the same table.

@sidorares
Copy link
Member

@ForbesLindesay you can always rename row in sql with value2 as baz. Alternatively we can have flag to output rows as an array instead of hash

@ForbesLindesay
Copy link
Author

A flag to output as an array instead of a hash would be really useful. The reason for this is that I use the column names directly as part of the report shown to the user so renaming them to random different things doesn't really completely solve the problem.

@sidorares
Copy link
Member

@felixge - your thoughts? It's easy addition, I'm probably +1 to "rowsAsArray" client flag

@felixge
Copy link
Collaborator

felixge commented Dec 27, 2013

@sidorares sure, an rowsAsArray option for the query() sounds great. Happy to merge a patch if somebody wants to implement it.

@sidorares
Copy link
Member

@felixge I can do this. should be in v2.1 imo as it's a new api. What do you think about 2.0 release?

@felixge
Copy link
Collaborator

felixge commented Dec 27, 2013

@sidorares I don't have time right now to cut a 2.0 release, but if you want to go ahead with it - go for it.

As for future version numbers: Incrementing to 2.x for new features makes sense. 3.x will be reserved if we have to make b/c breaking changes, but I'd like to avoid doing that unless we have very good reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants