pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
union & subqueries
2+ messages / 2 participants
[nested] [flat]

* union & subqueries
@ 2001-03-02 13:42 Martin Lillepuu <martin@lillepuu.com>
  2001-03-02 17:18 ` Re: union & subqueries Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Martin Lillepuu @ 2001-03-02 13:42 UTC (permalink / raw)
  To: pgsql-sql

hello,

when I run following sql in 2 separate queries, they work fine. but when
used as one beg statement with UNION, I get following error:

 join_references: variable not in subplan target lists

If I remove subqueries, they also work fine.

I'm currently using postgres 7.0.2. would upgrading to 7.0.3 or 7.1 beta
fix this? or is there a workaround for current version?

Query is supposed to get all AP/AR transactions with related
customer/vendor records and transactions expense/income account name
(with subquery). 

---- 8< ---- 8< ----

SELECT ar.id, ar.invnumber as source, ar.notes, customer.name,
customer.addr1, customer.addr2, customer.addr3,
acc_trans.transdate, ar.invoice, acc_trans.amount,
(
	SELECT C.description FROM chart C, acc_trans AT
	WHERE AT.trans_id = ar.id
	AND AT.amount > 0
	AND AT.amount=-ar.amount
	AND C.accno=AT.accno
) as desc,
'ar' as type
FROM ar, acc_trans
WHERE acc_trans.accno IN (1061,1065)
AND acc_trans.trans_id = ar.id
AND ar.customer = customer.id

UNION

SELECT ap.id, ap.ordnumber as source, ap.notes, vendor.name,
vendor.addr1, vendor.addr2, vendor.addr3,
acc_trans.transdate, ap.invoice, acc_trans.amount,
(
	SELECT C.description FROM chart C, acc_trans AT
	WHERE AT.trans_id = ap.id
	AND AT.amount < 0
	AND AT.amount=-ap.amount
	AND C.accno=AT.accno
) as desc,
'ap' as type
FROM ap, acc_trans
WHERE acc_trans.accno IN (1061,1065)
AND acc_trans.trans_id = ap.id
AND ap.vendor = vendor.id
ORDER BY transdate

---- 8< ---- 8< ----

--
Martin Lillepuu | E-mail: martin@lillepuu.com | GSM: 051 56 450



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: union & subqueries
  2001-03-02 13:42 union & subqueries Martin Lillepuu <martin@lillepuu.com>
@ 2001-03-02 17:18 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2001-03-02 17:18 UTC (permalink / raw)
  To: Martin Lillepuu <martin@lillepuu.com>; +Cc: pgsql-sql

Martin Lillepuu <martin@lillepuu.com> writes:
> when I run following sql in 2 separate queries, they work fine. but when
> used as one beg statement with UNION, I get following error:
>  join_references: variable not in subplan target lists

AFAICT this works OK in 7.1beta.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-03-02 17:18 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-02 13:42 union & subqueries Martin Lillepuu <martin@lillepuu.com>
2001-03-02 17:18 ` 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