Re: UPDATE crash in HEAD and 8.1

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: UPDATE crash in HEAD and 8.1
Date: 2006-06-20 17:48:59
Message-ID: 4498350B.1030204@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
>
>> update pk set id = max(id) + 2;
>>
>
> I'm fairly sure this query is illegal per spec. There are ancient
> discussions in the archives about whether aggregates in an UPDATE target
> list can have a consistent interpretation or not. We never found one,
> but never got around to disallowing it either. Maybe it's time. If you
> try it with something like sum() you don't get a crash, but you do get
> rather bizarre behavior.
>
> Having said that, this may well expose a bug in the MAX-optimization
> code that has consequences for more useful queries. I'll take a look
> later today if no one beats me to it.
>
>

If you try the query on 8.0 and before you don't get a crash either, but
the result is unexpected. Try this version:

create table pk (id bigserial primary key, orig bigint);
insert into pk (id) values (DEFAULT);
insert into pk (id) values (DEFAULT);
insert into pk (id) values (DEFAULT);
update pk set orig = id;
select * from pk;
update pk set id = max(id) + 2;
select * from pk;

One could almost argue that crashing would be better ;-)

cheers

andrew

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2006-06-20 18:03:13 Re: UPDATE crash in HEAD and 8.1
Previous Message Robert Lor 2006-06-20 17:44:43 Re: Generic Monitoring Framework Proposal