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

Поиск
Список
Период
Сортировка
От Leif Biberg Kristensen
Тема Re: Putting an aggregate value in an UPDATE statement...
Дата
Msg-id 201006012326.05068.leif@solumslekt.org
обсуждение исходный текст
Ответ на Re: Putting an aggregate value in an UPDATE statement...  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Putting an aggregate value in an UPDATE statement...  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
> 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.

A couple of days ago, a was a little stumped by this. I had written a plain
SQL function with one integer parameter, and then tried to use a SELECT as
input parameter as in

SELECT myfunc(SELECT foo FROM bar WHERE baz);

It took a while before I realized that I needed to put the query in another
set of parentheses:

SELECT myfunc((SELECT foo FROM bar WHERE baz));

worked just fine. I fail to see the ambiguity here, though.

regards,
--
Leif Biberg Kristensen
http://solumslekt.org/blog/

В списке pgsql-novice по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Putting an aggregate value in an UPDATE statement...
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Putting an aggregate value in an UPDATE statement...