From: | Martin Lillepuu <martin(at)lillepuu(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | union & subqueries |
Date: | 2001-03-02 13:42:43 |
Message-ID: | 3A9FA353.EE681533@lillepuu.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)lillepuu(dot)com | GSM: 051 56 450
From | Date | Subject | |
---|---|---|---|
Next Message | Sondaar Roelof | 2001-03-02 14:09:32 | RE: Help creating rules/triggers/functions |
Previous Message | Thomas Lockhart | 2001-03-02 13:30:38 | Re: [HACKERS] why the DB file size does not reduce when 'delete' the data in DB? |