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

Duplicate column name while aggregating #34096

Closed
rafallyczkowski opened this issue Sep 2, 2020 · 2 comments
Closed

Duplicate column name while aggregating #34096

rafallyczkowski opened this issue Sep 2, 2020 · 2 comments
Labels

Comments

@rafallyczkowski
Copy link

rafallyczkowski commented Sep 2, 2020

  • Laravel Version: 7.27.0
  • PHP Version: 7.4.9
  • Database Driver & Version: MariaDB 10.5.5 MySQL

Description:

For aggregate selects it's forbidden to have a duplicated column names.

[2020-09-01 18:59:47] local.ERROR: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'description' (SQL: ... at /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671)

Steps To Reproduce:

Execute this query.

$count = DB::query()->fromSub(function ($query) {
   $query
       ->from('users')
       ->addSelect('email')
       ->addSelect('email')
       ->groupBy('email');
}, 'a')->count();

Motivation

When using a repositories design patter, we are having criteria that build a query based on the data in the specific criteria,
we don't check on this level agains existing columns. I believe array_unique could be executed on the columns just before sending a query. It does not affect any column select aliases.

#34097

@taylorotwell
Copy link
Member

If you would like to submit a PR to run array_unique feel free.

@saltamay
Copy link

saltamay commented Jan 6, 2021

Can anyone please confirm that this was indeed resolved? I can't seem to find the changes in the production code. It seems that the changes went into a fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants