pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedQuery broken under 7.1RC2
2+ messages / 2 participants
[nested] [flat]
* Query broken under 7.1RC2
@ 2001-04-04 15:24 Kyle <kyle@actarg.com>
0 siblings, 1 reply; 2+ messages in thread
From: Kyle @ 2001-04-04 15:24 UTC (permalink / raw)
To: pgsql-sql; +Cc: tgl@sss.pgh.pa.us
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Query broken under 7.1RC2
@ 2001-04-04 15:54 Tom Lane <tgl@sss.pgh.pa.us>
parent: Kyle <kyle@actarg.com>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2001-04-04 15:54 UTC (permalink / raw)
To: Kyle <kyle@actarg.com>; +Cc: pgsql-sql
Kyle <kyle@actarg.com> writes:
> 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.
It is bad SQL, but pre-7.1 Postgres failed to catch it. Here's the
CVS log entry:
2000-09-25 14:09 tgl
* src/backend/optimizer/plan/planner.c: System neglected to
complain about ungrouped variables passed to sublinks when outer
query contained aggregates but no GROUP clause.
Since you have a SUM(), the outer query is a grouped query, and so
references to the ungrouped h.* columns in the SELECT targetlist are
not well defined. Lord knows what result you were getting from 7.0 ...
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-04-04 15:54 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-04 15:24 Query broken under 7.1RC2 Kyle <kyle@actarg.com>
2001-04-04 15:54 ` Tom Lane <tgl@sss.pgh.pa.us>
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