rowset.iterator().next().toJson() removes (wrongly) duplicate columns
blackblather opened this issue · 2 comments
Version
4.3.0
Context
Suppose you have 2 tables:
Employee
id | name | company_id |
---|---|---|
111 | Bob | C1 |
222 | Alice | C2 |
Company
id | name |
---|---|
C1 | Company 1 |
C2 | Company 2 |
When you run the following query directly in your RDBMS
SELECT *
FROM Employee
INNER JOIN Company ON Employee.company_id = Company.id
WHERE Employee.id = 111;
The result is something like this:
Employee.id | Employee.name | company_id | Company.id | Company.name |
---|---|---|---|---|
111 | Bob | C1 | C1 | Company 1 |
NOTE: Notice how the columns with duplicate names are prepended with the table name to avoid colisions.
However, when you do rowset.columnsNames()
the resulting List elements are not prepended with the table name.
You get something like:
Index --> Value
0 --> "id"
1 --> "name"
2 --> "company_id"
3 --> "id"
4 --> "name"
This behaviours seems to propagate further. For instance, when you do rowset.iterator().next().toJson()
, the resulting JSON object is something like:
{
"id": "C1",
"name": "Company ",
"company_id": "C1"
}
This is a legitimate use case.
I am running a costly query with many INNER JOINs
, and to avoid making multiple requests to the DB, I make one where i SELECT * etc...
and handle the mapping of the result to my Entity objects manually in the server code.
With this current behaviour, I cannot rely on vertx if I want to simply SELECT * etc...
.
I have to instead to use aliases like so SELECT Employee.id AS employee_id, Employee.name AS employee_name, Company.id AS company_id, Company.name AS company_name etc...
, which is not ideal for large tables.
Thanks in advance : D
This has been reported already, but there's not much we can do about it, see #1279 (comment)
You are right.
When running the query directly in IntellIj, the IDE prepends the result with the table name in case of a conflict.
I tried running the same query with PSQL this time and it does not prepend anything.
Thanks for the fast response 👌