Re: FIRST_VALUE: need to group by argument?

From: Manuel Gómez <targen(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Guyren Howe <guyren(at)gmail(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: FIRST_VALUE: need to group by argument?
Date: 2016-05-24 16:12:59
Message-ID: CAJWnFaO6GcbhoJS8Rjo1Jf8brCPDOPPufkt-aBC2iK+oU1LuTA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 24, 2016 at 8:50 AM, David G. Johnston
<david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
> SELECT x, sum(i), sum(sum(i)) OVER (PARTITION BY x) FROM ( VALUES (a,1),
> (a,2), (b,3) ) val (x,i) GROUP BY x
> yields
> a, 3, 6
> b, 3, 6

Thank you for this enlightening explanation! I was, however, very
confused from this specific bit, so I tested it and indeed there must
have been a typo:

postgres=# SELECT x, sum(i), sum(sum(i)) OVER (PARTITION BY x) FROM
(VALUES ('a', 1), ('a', 2), ('b', 3)) val (x,i) GROUP BY x;
x | sum | sum
---+-----+-----
a | 3 | 3
b | 3 | 3
(2 rows)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2016-05-24 16:17:21 Re: pg_upgrade error regarding hstore operator
Previous Message Alvaro Herrera 2016-05-24 16:00:17 Re: ERROR: MultiXactId xxx has not been created yet