Re: invalid reference to FROM-clause entry for table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sam Stearns <sam(dot)stearns(at)dat(dot)com>
Cc: pgsql-sql(at)lists(dot)postgresql(dot)org, Peter Garza <peter(dot)garza(at)dat(dot)com>, Henry Ashu <henry(dot)ashu(at)dat(dot)com>
Subject: Re: invalid reference to FROM-clause entry for table
Date: 2024-10-03 22:21:32
Message-ID: 472955.1727994092@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Sam Stearns <sam(dot)stearns(at)dat(dot)com> writes:
> This one is really doing my head in:
> ...
> FROM (pud_fme_data d
> inner join csbuser u on (u.userid=d.user_id)
> inner join office o on (u.officeid=o.officeid)
> left outer join login l on (l.userid=u.userid) ) alias6;

> ERROR: invalid reference to FROM-clause entry for table "o"
> LINE 2: o.crmaccountid AS crm_account_id,
> ^
> DETAIL: There is an entry for table "o", but it cannot be referenced from
> this part of the query.

IIRC, the join alias "alias6" hides any table aliases inside it.
Leave that off. Or reference the column as "alias6.crmaccountid".
(This way might require fooling around with column aliases so that
crmaccountid is a unique column name within that scope.)

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Adw Spe 2024-10-04 13:27:31 RE: invalid reference to FROM-clause entry for table
Previous Message Sam Stearns 2024-10-03 22:14:46 invalid reference to FROM-clause entry for table