Re: ERROR: missing FROM-clause entry for table

From: Vik Fearing <vik(at)2ndquadrant(dot)fr>
To: Kevin Waterson <kevin(dot)waterson(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: ERROR: missing FROM-clause entry for table
Date: 2016-02-21 13:38:56
Message-ID: 56C9BDF0.4060500@2ndquadrant.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message tuanhoanganh 2016-02-21 16:45:01 Re: Why Postgres use a little memory on Windows.
Previous Message Kevin Waterson 2016-02-21 13:22:45 ERROR: missing FROM-clause entry for table