From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Gilbert <dgilbert@velocet.ca>
Cc: pgsql-admin@postgresql.org
Subject: Re: Query failing with strange error.
Date: Wed, 15 Jan 2003 10:45:52 -0500
Message-ID: <5018.1042645552@sss.pgh.pa.us> (raw)
In-Reply-To: <15909.30064.257538.752011@canoe.velocet.net>
References: <15909.30064.257538.752011@canoe.velocet.net>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, dgilbert@velocet.ca
Subject: Re: Query failing with strange error.
In-Reply-To: <5018.1042645552@sss.pgh.pa.us>
References: <15909.30064.257538.752011@canoe.velocet.net> <5018.1042645552@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox