Re: Putting an aggregate value in an UPDATE statement...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: John Gage <jsmgage(at)numericable(dot)fr>
Cc: Bret Fledderjohn <freelancer317(at)gmail(dot)com>, NOVICE Postgres elist <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Putting an aggregate value in an UPDATE statement...
Date: 2010-06-01 21:15:52
Message-ID: 9432.1275426952@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

John Gage <jsmgage(at)numericable(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Leif Biberg Kristensen 2010-06-01 21:26:05 Re: Putting an aggregate value in an UPDATE statement...
Previous Message Leif Biberg Kristensen 2010-06-01 21:15:13 Re: Putting an aggregate value in an UPDATE statement...