Re: aggregate functions are not allowed in UPDATE

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: aggregate functions are not allowed in UPDATE
Date: 2019-01-15 16:52:11
Message-ID: CAADeyWiVAsnox5NBp5YMKHVgGT7VR0uACLXUR6O8hWsdQ0xsfQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Unfortunately, I don't understand your advice, David -

On Tue, Jan 15, 2019 at 5:46 PM David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> On Tue, Jan 15, 2019 at 9:42 AM Alexander Farber
> <alexander(dot)farber(at)gmail(dot)com> wrote:
> > When I am trying
> >
> > WITH diffs AS (
> > SELECT
> > gid,
> > uid,
> > played - LAG(played) OVER(PARTITION BY gid ORDER BY played) AS diff
> > FROM moves
> > WHERE uid = 1
> > )
> > UPDATE users SET
> > avg_time = TO_CHAR(AVG(diff), 'HH24:MI')
> > FROM diffs;
> >
> > the syntax error is unfortunately printed by PostgreSQL 10:
> >
> > aggregate functions are not allowed in UPDATE
>
> So calculate the average somewhere else, put the result in a column,
> and then reference that column in the SET clause.
>
>
do you suggest to add a second CTE?

Regards
Alex

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2019-01-15 16:58:51 Re: aggregate functions are not allowed in UPDATE
Previous Message David G. Johnston 2019-01-15 16:46:32 Re: aggregate functions are not allowed in UPDATE