Re: cannot find source of "add missing from" error - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: cannot find source of "add missing from" error
Date
Msg-id 20051207125037.GB3450@svana.org
Whole thread Raw
In response to cannot find source of "add missing from" error  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: cannot find source of "add missing from" error
List pgsql-general
On Wed, Dec 07, 2005 at 10:10:40AM +0100, Karsten Hilbert wrote:
> Hello,
>
> I have a slightly involved view that draws from other views.
> Upon insertion into the database (creation) it complains of
>
> ERROR:  missing FROM-clause entry in subquery for table "v_basic_person"
>
> and I can't for the life of it find why (I know I can work
> around this with a postgresql.conf option).

<snip>

> from
>     clin.v_pat_items vpi,
>     clin.clin_hx_family chxf,
>     clin.hx_family_item hxfi,
>     v_basic_person vbp                            <----------
> where
>     vpi.pk_item = chxf.pk_item
>         and
>     hxfi.pk = chxf.fk_hx_family_item
>         and
>     hxfi.fk_narrative_condition is null
>         and
>     hxfi.fk_relative = v_basic_person.pk_identity      <-----------
>

You can't alias a table and then use the original table name because
that refers to a different table. That's why this error message exists.
You should use vbp.pk_identity.

Note, one of the legs of your union has v_basic_person in the FROM but
doesn't use it. The effect is probably hidden due to your use of UNION
rather than UNION ALL.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: "Daniel Verite"
Date:
Subject: Re: Character encoding and string matches
Next
From: Martijn van Oosterhout
Date:
Subject: Re: PostgreSQL 8.1.0 RHEL / Debian incompatible packages