Thread: ERROR: missing FROM-clause entry for table

ERROR: missing FROM-clause entry for table

From
Kevin Waterson
Date:
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
                            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...
                        

Re: ERROR: missing FROM-clause entry for table

From
Vik Fearing
Date:
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