From: Kyle <kyle@actarg.com>
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Query broken under 7.1RC2
Date: Wed, 04 Apr 2001 09:24:41 -0600
Message-ID: <3ACB3CB9.CB5F0C46@actarg.com> (raw)
This query worked under 7.0.3 but yields an error under 7.1RC1 or RC2.
The error message is:
psql:outbug.sql:43: ERROR: Sub-SELECT uses un-GROUPed attribute
h.ordnum from outer query
Tom, you patched util/clauses.c (near line 540) a while back to prevent
the same error message on a different query. This may be related.
The SQL is a little strange because the subquery tries to reference
individual records from the outer query and then sum them.
The more I look at it, I wonder if it is not just bad SQL. But the last
one I found like this turned out to reveal a bug, so here it is:
drop table ord_hdr;
drop table cinv_hdr;
drop table cinv_items;
drop table inc_link;
create table ord_hdr (
ordnum int4,
proj int4
);
create table cinv_hdr (
ordnum int4,
hinum int4,
status varchar
);
create table cinv_items (
ordnum int4,
hinum int4,
quant int4,
unit_price numeric(12,2)
);
create table inc_link (
ordnum int4,
hinum int4,
amount numeric(12,2)
);
select sum(i.quant*i.unit_price::float8),
(select coalesce(sum(amount),0) from inc_link where ordnum = h.ordnum
and hinum = h.hinum)
from cinv_hdr h, cinv_items i, ord_hdr o where
o.ordnum = h.ordnum and
h.ordnum = i.ordnum and
h.hinum = i.hinum and
o.proj = 1051 and
h.status = 'open'
;
Attachments:kyle.vcf (text/x-vcard, 184B) download
begin:vcard
n:Bateman;Kyle
x-mozilla-html:FALSE
org:Action Target Inc.
adr:;;;;;;
version:2.1
email;internet:kyle@actarg.com
title:President
x-mozilla-cpt:;0
fn:Kyle Bateman
end:vcard
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-sql@postgresql.org
Cc: kyle@actarg.com, tgl@sss.pgh.pa.us
Subject: Re: Query broken under 7.1RC2
In-Reply-To: <3ACB3CB9.CB5F0C46@actarg.com>
References: <3ACB3CB9.CB5F0C46@actarg.com>
* 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