Re: Query failing with strange error.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Query failing with strange error.
Дата
Msg-id 5018.1042645552@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Query failing with strange error.  (David Gilbert <dgilbert@velocet.ca>)
Список pgsql-admin
David Gilbert <dgilbert@velocet.ca> writes:
> update customer_contact
>  set next_billed=min(customer_services.eff_date)
>  where customer_contact.conn_num=7698
>   and customer_services.conn_num=7698
>   and customer_services.inv_num=0

This is not a well-defined query --- exactly what do you think the
semantics should be?  Over what set of rows is the MIN() taken, for
any particular target row to be updated?  With only one WHERE clause,
you've got no way to control the set of rows the MIN() scans separately
from the set of rows the UPDATE targets.

SQL92 forbids such things outright:

         <update statement: searched> ::=
              UPDATE <table name>
                SET <set clause list>
                [ WHERE <search condition> ]

         Syntax Rules

         2) A <value expression> in a <set clause> shall not directly con-
            tain a <set function specification>.

Postgres doesn't presently forbid it, but we probably should, because
the executor tends to get confused --- unsurprisingly considering that
there's no well-defined behavior for this case.

What I think you mean is

update customer_contact
 set next_billed =
  (SELECT min(customer_services.eff_date) FROM customer_services
   where customer_services.conn_num=7698
   and customer_services.inv_num=0)
 where conn_num=7698

but that's just a guess about the intended behavior.

            regards, tom lane

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

Предыдущее
От: Andre Schubert
Дата:
Сообщение: Re: Problems with PGOPTIONS
Следующее
От: "Gareth Kirwan"
Дата:
Сообщение: pg_dumpall and large flat file