Skip to content

Bug: Does not correctly return a result with duplicate keys #1445

Open
@rathboma

Description

@rathboma

Hey folks,

First - thank you for maintaining this library. It is excellent.

I'm the maintainer of Beekeeper Studio, an open source desktop SQL client.

One problem that keeps coming up is that our users will run a query with duplicate column names and get super confused at the result

For example:

select 1 as foo, 2 as foo

The result of this query is [ { foo: 2 } ], which is incorrect.

image

Is this a bug?

When using the sqlite command line client you get 2 results, 1, 2, as expected. This is also true in many database client apps like DBeaver, etc.

I understand that renaming the columns is the sql-way to fix this, but I don't get to control that, instead I get upset or angry users who are confused :-).

I can also see how this could lead to some major, if subtle, bugs in applications that use the library for their production database.

Proposed solution

I've recently fixed this bug for both PSQL and MySQL2 by using an option that forces results as an array rather than an object, in our example it would return something like below:

{
  "fields": ["foo", "foo"],
  "data": [ [1, 2] ]
}

Is something like this possible? I know currently the driver doesn't return a separate fields key, so it would be a different return signature.

If so -- I'm super happy to work on this feature if you can provide me with some direction as to where it should be implemented.

Thanks again,

Matthew

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions