Re: Putting an aggregate value in an UPDATE statement... - Mailing list pgsql-novice

From Tom Lane
Subject Re: Putting an aggregate value in an UPDATE statement...
Date
Msg-id 9432.1275426952@sss.pgh.pa.us
Whole thread Raw
In response to Re: Putting an aggregate value in an UPDATE statement...  (John Gage <jsmgage@numericable.fr>)
Responses Re: Putting an aggregate value in an UPDATE statement...
List pgsql-novice
John Gage <jsmgage@numericable.fr> writes:
> Thanks.  I tried that _without_ the parentheses around the select
> statement and it didn't work.

> At the risk of further displaying ignorance, why are the parens
> necessary, what do they do?

You need them to syntactically separate the sub-select from the outer
select.  If SQL didn't require them, then in something like

    UPDATE question_choices SET total_rows =
        select count(*) from care_lesson where something

it wouldn't be clear whether the WHERE clause was meant to attach
to the sub-select or the outer UPDATE.

            regards, tom lane

pgsql-novice by date:

Previous
From: Leif Biberg Kristensen
Date:
Subject: Re: Putting an aggregate value in an UPDATE statement...
Next
From: Leif Biberg Kristensen
Date:
Subject: Re: Putting an aggregate value in an UPDATE statement...