-
Notifications
You must be signed in to change notification settings - Fork 378
Description
Hi,
For queries with joins, we occasionally end up with situations where a column name becomes ambiguous and we need to qualify it with the table / alias - as an example, our hand-rolled SQL generated created the following SQL from our test samples:
SELECT order_table.orderline AS "orderline", customer_table.customer_name AS "customerName", customer_address.street_name AS "customerAddress", warehouse_address.street_name AS "warehouseAddress"
FROM order_table
JOIN customer_table ON order_table.customer_id = customer_table.address_id
JOIN address_table customer_address ON customer_table.address_id = customer_address.address_id
JOIN address_table warehouse_address ON order_table.address_id = warehouse_address.address_id
WHERE warehouse_address.street_name = :warehouse AND customer_table.customer_name = :customerName AND customer_address.street_name = :customerAddress
ORDER BY customer_address.street_name ASC, warehouse_address.street_name ASCWhen migrating our SQL generator to generate Select and use the SelectRenderer, we discovered that the generated ORDER BY clause became ORDER BY street_name ASC, street_name ASC. This is ambiguous as street_name is defined from multiple sources (once from customer_address and once from warehouse_address).
As a work around, I have migrated it to use the aliased columns, which mitigates the problem as long as the ORDER BY only references columns that are SELECT'ed. In at least PostgreSQL, you can include other columns in ORDER BY, so we would like this to be supported via Spring as well.