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

Not working in Postgres - GROUPBY error in SQL syntax #174

Closed
suchal opened this issue Oct 20, 2016 · 2 comments
Closed

Not working in Postgres - GROUPBY error in SQL syntax #174

suchal opened this issue Oct 20, 2016 · 2 comments
Assignees

Comments

@suchal
Copy link

suchal commented Oct 20, 2016

Error:

SQLSTATE[42803]: Grouping error: 7 ERROR: column "participants.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select * from "threads" where exists (select * from "partici...
^ (SQL: select * from "threads" where exists (select * from "participants" where "participants"."thread_id" = "threads"."id" and "user_id" in (2, 1) and "participants"."deleted_at" is null group by "thread_id" having COUNT(thread_id)=2) and "threads"."deleted_at" is null limit 1)

SQLSTATE[42803]: Grouping error: 7 ERROR: column "participants.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select * from "threads" where exists (select * from "partici...
^

Code:
in MessagesController

    public function show($username){
        $user = User::where('username', $username)->first();
        $authUser = \Auth::user();
        if(! $user)
            abort(404, 'user not found');
        if($thread = Thread::Between([$user->id, $authUser->id])->first())
            $thread->load(['participants', 'messages.user']);
        return view('messages.show', compact('thread', 'user'));
    }

Environment:

  • Laravel 5.3
  • Postgres SQL server on Amazon AWS
  • Local environment on Laravel Homestead with everything updated to the latest version
  • cmgmyr/laravel-messenger: ^2.13
  • Works on mysql but with only strict mode disabled.

How to replicate the error?

  • Change the database to postgres in .env file and provide the necessary credentials.
  • run the migrations
  • Use the Scope Between on Thread class.
@cmgmyr
Copy link
Owner

cmgmyr commented Nov 3, 2016

@suchal thanks for reporting this, and all of the additional details - it's certainly helpful. I'm still looking into this but hopefully should have a solution soon.

@cmgmyr cmgmyr self-assigned this Nov 11, 2016
@cmgmyr
Copy link
Owner

cmgmyr commented Nov 11, 2016

@suchal can you update composer to point to dev-bug/#174-postgres-between-fix? Seems to be working in Homestead for me

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