Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id EAD2447705A for ; Wed, 15 Jan 2003 11:16:39 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 44BB6477246 for ; Wed, 15 Jan 2003 10:45:48 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h0FFjq5u005019; Wed, 15 Jan 2003 10:45:52 -0500 (EST) To: David Gilbert Cc: pgsql-admin@postgresql.org Subject: Re: Query failing with strange error. In-reply-to: <15909.30064.257538.752011@canoe.velocet.net> References: <15909.30064.257538.752011@canoe.velocet.net> Comments: In-reply-to David Gilbert message dated "Wed, 15 Jan 2003 09:51:28 -0500" Date: Wed, 15 Jan 2003 10:45:52 -0500 Message-ID: <5018.1042645552@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/161 X-Sequence-Number: 7003 David Gilbert 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 SET [ WHERE ] Syntax Rules 2) A in a shall not directly con- tain a . 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