Re: ERROR: missing FROM-clause entry for table - Mailing list pgsql-general

From Vik Fearing
Subject Re: ERROR: missing FROM-clause entry for table
Date
Msg-id 56C9BDF0.4060500@2ndquadrant.fr
Whole thread Raw
In response to ERROR: missing FROM-clause entry for table  (Kevin Waterson <kevin.waterson@gmail.com>)
List pgsql-general
On 02/21/2016 02:22 PM, Kevin Waterson wrote:
> I do not understand why I am getting this error.
> I have joined the table correctly, is this not sufficient?
>
> forge=> select * FROM generate_series('2016-01-22', '2017-12-31', '1
> day'::interval) AS day
> LEFT JOIN (
>                             select *, generate_series(c.start_time,
> c.end_time, '2 week'::interval) meeting
>                             from call_schedule c
>                             join call_durations cds on
> c.duration_id=cds.id <http://cds.id>
>                             where call_frequency_id = 5
>                         ) c on ((day, '1 day'::interval) OVERLAPS
> (meeting, cds.duration * '1s'::interval));
> ERROR:  missing FROM-clause entry for table "cds"
> LINE 7: ...c on ((day, '1 day'::interval) OVERLAPS (meeting, cds.durati...

Once you leave the subquery, cds ceases to exist.  You need to add
something like  cds.duration as cds_duration  to your subquery's select
and then you can use  c.cds_duration  in your join clause.

Since your subquery already has *, if the column duration is not
ambiguous you can just join using  c.duration  but it's usually best to
only select the columns you need.
--
Vik Fearing                                          +33 6 46 75 15 36
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support


pgsql-general by date:

Previous
From: Kevin Waterson
Date:
Subject: ERROR: missing FROM-clause entry for table
Next
From: tuanhoanganh
Date:
Subject: Re: [PERFORM] Why Postgres use a little memory on Windows.