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

[5.7] Fix UNION aggregate queries with columns #26466

Merged
merged 1 commit into from
Nov 10, 2018
Merged

[5.7] Fix UNION aggregate queries with columns #26466

merged 1 commit into from
Nov 10, 2018

Conversation

staudenmeir
Copy link
Contributor

@staudenmeir staudenmeir commented Nov 10, 2018

UNION aggregate queries don't apply the selected columns to the base query:

DB::table('posts')->select('id')->union(
  DB::table('videos')->select('id')
)->count()
# expected
select count(*) as aggregate from (
  (select `id` from `posts`) union (select `id` from `videos`)
) as `temp_table`

# actual
select count(*) as aggregate from (
  (select * from `posts`) union (select `id` from `videos`)
          ^
) as `temp_table`

The selected columns are irrelevant for the result, but the UNION query doesn't work with different numbers of columns ("cardinality violation").

This also affects pagination queries.

Fixes #26444.

@taylorotwell taylorotwell merged commit ddb907a into laravel:5.7 Nov 10, 2018
@staudenmeir staudenmeir deleted the union-pagination branch November 10, 2018 16:36
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

Successfully merging this pull request may close these issues.

2 participants