pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Alexander Farber <alexander.farber@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Counting booleans in GROUP BY sections
Date: Fri, 29 Nov 2019 12:55:26 -0800
Message-ID: <082dc4bf-e668-f091-9d96-9725dd5ddfee@aklaver.com> (raw)
In-Reply-To: <CAADeyWi61hM44YjfYaiNLn5apXWM9bEiv1Hn=+U6Lxe0b6E6Lw@mail.gmail.com>
References: <CAADeyWhQTjAFfE-ZhgpJL9HJRw3HJdd1bGUPOuyQUBGpHbrRGQ@mail.gmail.com>
	<f46ad34a-ec3f-ae79-31ba-d9fa46ed8274@aklaver.com>
	<CAADeyWi61hM44YjfYaiNLn5apXWM9bEiv1Hn=+U6Lxe0b6E6Lw@mail.gmail.com>

On 11/29/19 11:47 AM, Alexander Farber wrote:
> Thank you Adrian, but -

> 
> if I remove GROUP BY mid, then I get the error:
> 
> ERROR:  42803: column "words_moves.mid" must appear in the GROUP BY 
> clause or be used in an aggregate function
> LINE 18:         mid,
>                   ^
> LOCATION:  check_ungrouped_columns_walker, parse_agg.c:1369

Yes because it is a case of opposing forces. When you remove mid from 
the GROUP BY you get an single row for each group that has an aggregated 
output where you can have count of > 1. In that case the database has 
more then one choice for the mid to display and so it throws the error.

To go forward it would help to know what it is you are trying to achieve?

> 
> Regards
> Alex


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (7+ messages)  latest in thread

Message-ID: <082dc4bf-e668-f091-9d96-9725dd5ddfee@aklaver.com>
Permalink:  ../082dc4bf-e668-f091-9d96-9725dd5ddfee@aklaver.com/
Also on:    postgresql.org/message-id/082dc4bf-e668-f091-9d96-9725dd5ddfee@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, alexander.farber@gmail.com
  Subject: Re: Counting booleans in GROUP BY sections
  In-Reply-To: <082dc4bf-e668-f091-9d96-9725dd5ddfee@aklaver.com>
  References: <CAADeyWhQTjAFfE-ZhgpJL9HJRw3HJdd1bGUPOuyQUBGpHbrRGQ@mail.gmail.com> <f46ad34a-ec3f-ae79-31ba-d9fa46ed8274@aklaver.com> <CAADeyWi61hM44YjfYaiNLn5apXWM9bEiv1Hn=+U6Lxe0b6E6Lw@mail.gmail.com> <082dc4bf-e668-f091-9d96-9725dd5ddfee@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox