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

Don't add selecting of all fields if not needed #10

Open
lespavl opened this issue Apr 24, 2015 · 3 comments
Open

Don't add selecting of all fields if not needed #10

lespavl opened this issue Apr 24, 2015 · 3 comments

Comments

@lespavl
Copy link

lespavl commented Apr 24, 2015

I'm using Postgresql and have the following code:

$items = Element::select(DB::raw("COUNT(1), category"))->groupBy('category')->get();

Mysql processes this query without any problems, but in case of Postgresql I'm getting an error:

column "id" must appear in the GROUP BY clause or be used in an aggregate function

That's because your package adds extra select elements.* and Postgresql works in such way, that I need to specify, what to do with each selected field.

@crissi
Copy link

crissi commented Apr 30, 2015

Same problem seems to be adding table.* on the query even though you already have table.* on your select. It is in sql server. On Mysql it is doing fine

@indratjhai
Copy link

I've just found out that this will also be an issue when doing union queries
This package is selecting all columns on all select statements in union queries, making the column numbers do not agree if we're union-ing different tables with different column numbers.

Exception thrown:

SQLSTATE[21000]: Cardinality violation: 1222 The used SELECT statements have a different number of columns

Example of generated query:

(select A, B, table1.* from table1) # table1 has 3 columns
union
(select A, B, table2.* from table2) # table2 has 4 columns

Temporary workaround is to use Laravel's query builder (DB class) instead of table's model when doing unions.

@xxxcoltxxx
Copy link

+1

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

4 participants