Skip to content
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

Union of queries with differently derived columns loses the derived columns #1373

Closed
dinoklein-ls opened this issue Oct 30, 2021 · 2 comments

Comments

@dinoklein-ls
Copy link

dinoklein-ls commented Oct 30, 2021

Here's a simplified SQL query to represent the problem I've encountered:

SELECT T1.id, T1.amount * 10 AS value FROM T1
UNION ALL
SELECT T1.id, T1.amount * 100 AS value FROM T1

Then lets say have this code to fetch the data:

val q1: Query
val q2: Query
val data = q1.unionAll(q2).alias("data").selectAll()

When inspecting the data returned, only the ID field is present, while the derived column is omitted.

The generated SQL that is logged by exposed is basically like this:

SELECT "data".id FROM (
-- union query per above
) AS "data"

Hence, the derived columns, while present in the subqueries, were completely omitted from the top-level select.
I have noticed when I was dumping data from each query individually that the full formula for each derived column was part of its name/structure, hence leading me to believe that columns are not matched based on their type, and ultimately excluded from the union's column set based on a perceived mismatch -- but this is conjecture on my part.

That said, there is a gap here in being able to fetch data, and a question on how one would fetch the data if it were present, but that was already raised as issue #1253.

This was observed with version 0.35.3.

@dinoklein-ls dinoklein-ls changed the title Union of queries with differently derived columns looses the derived columns Union of queries with differently derived columns loses the derived columns Nov 1, 2021
@Tapac Tapac closed this as completed Nov 8, 2021
@dinoklein-ls
Copy link
Author

@Tapac can you write a few words on how to fetch the data a union-ed column that has two different expression definitions? Will either "expression" object work to fetch it?

@Tapac
Copy link
Contributor

Tapac commented Nov 8, 2021

@dinoklein-ls, you can check related tests here.
It will work with the next release (0.36.2)

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

No branches or pull requests

2 participants