DDC-1773: GRUOP BY table.id in PostgreSQL. #2230

Closed
opened 2026-01-22 13:45:39 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 8, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user elfet:

I use in mysql driver this DQL: "GRUOP BY table.id"
But when i shwich to PostgreSQL i have to rewrite it like this: "GRUOP BY table"

Originally created by @doctrinebot on GitHub (Apr 8, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user elfet: I use in mysql driver this DQL: "GRUOP BY table.id" But when i shwich to PostgreSQL i have to rewrite it like this: "GRUOP BY table"
admin added the Bug label 2026-01-22 13:45:39 +01:00
admin closed this issue 2026-01-22 13:45:40 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 21, 2012):

Comment created by @FabioBatSilva:

Hi Elfet

I can't reproduce.

Could you give more details, maybe attach your entities or a test case ?

Thanks

@doctrinebot commented on GitHub (Apr 21, 2012): Comment created by @FabioBatSilva: Hi Elfet I can't reproduce. Could you give more details, maybe attach your entities or a test case ? Thanks
Author
Owner

@doctrinebot commented on GitHub (Apr 21, 2012):

Comment created by elfet:

The DQL: SELECT g, COUNT(u.id) AS usersCount FROM Entity\Group g LEFT JOIN g.users u GROUP BY g{color:red}.id{color}

The Entity

namespace Entity;

/****
 * @Entity(repositoryClass="Repository\Groups")
 */
class Group extends \System\Entity
{
    /*** @Id @Column(type="integer") @GeneratedValue **/
    protected $id;

    /*** @Column(length=100) **/
    protected $name;

    /*** @OneToMany(targetEntity="User", mappedBy="group") **/
    protected $users;
}

namespace Entity;

/****
 * @Entity(repositoryClass="Repository\Users") 
 */
class User extends \System\Entity
{
    /*** @Id @Column(type="integer") @GeneratedValue **/
    protected $id;

    /*** @Column(length=100) **/
    protected $name;

    /*** @Column **/
    protected $password;

    /*** @ManyToOne(targetEntity="Group", inversedBy="users") **/
    protected $group;

    public function **construct()
    {
        $this->logins = new \Doctrine\Common\Collections\ArrayCollection();
        $this->group = new Group()
    }
}
@doctrinebot commented on GitHub (Apr 21, 2012): Comment created by elfet: The DQL: SELECT g, COUNT(u.id) AS usersCount FROM Entity\Group g LEFT JOIN g.users u GROUP BY g{color:red}<ins>.id</ins>{color} The Entity ``` namespace Entity; /**** * @Entity(repositoryClass="Repository\Groups") */ class Group extends \System\Entity { /*** @Id @Column(type="integer") @GeneratedValue **/ protected $id; /*** @Column(length=100) **/ protected $name; /*** @OneToMany(targetEntity="User", mappedBy="group") **/ protected $users; } namespace Entity; /**** * @Entity(repositoryClass="Repository\Users") */ class User extends \System\Entity { /*** @Id @Column(type="integer") @GeneratedValue **/ protected $id; /*** @Column(length=100) **/ protected $name; /*** @Column **/ protected $password; /*** @ManyToOne(targetEntity="Group", inversedBy="users") **/ protected $group; public function **construct() { $this->logins = new \Doctrine\Common\Collections\ArrayCollection(); $this->group = new Group() } } ```
Author
Owner

@doctrinebot commented on GitHub (Apr 21, 2012):

Comment created by @FabioBatSilva:

Hi Elfet.

In some databases like postgres and oracle all selected columns must appear in the GROUP BY clause or be used in an aggregate function.
You CANNOT, select "Group" fields without add these field on the ORDER BY clause.

you should use :
( GROUP BY g )
or
( GROUP BY g.id, g.nome, g.otherSelectedFields )

@doctrinebot commented on GitHub (Apr 21, 2012): Comment created by @FabioBatSilva: Hi Elfet. In some databases like postgres and oracle all selected columns must appear in the GROUP BY clause or be used in an aggregate function. You CANNOT, select "Group" fields without add these field on the ORDER BY clause. you should use : ( GROUP BY g ) or ( GROUP BY g.id, g.nome, g.otherSelectedFields )
Author
Owner

@doctrinebot commented on GitHub (Apr 22, 2012):

Comment created by elfet:

Ok, thanks!

@doctrinebot commented on GitHub (Apr 22, 2012): Comment created by elfet: Ok, thanks!
Author
Owner

@doctrinebot commented on GitHub (Apr 22, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Apr 22, 2012): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2230