pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Gauthier <davegauthierpg@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: nested query problem
Date: Thu, 06 Sep 2018 17:11:37 -0400
Message-ID: <19947.1536268297@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMBRECCCSqSRZnBz2--ShfaP9fhkJYMVu+zktj6CEuZuT6Ovww@mail.gmail.com>
References: <CAMBRECCCSqSRZnBz2--ShfaP9fhkJYMVu+zktj6CEuZuT6Ovww@mail.gmail.com>

David Gauthier <davegauthierpg@gmail.com> writes:
> I'm having trouble with this query...

> select sr.sqf_id, sr.status, fse.perl_sub_name, fse.end_datetime
>   from
>     sqf_runs sr,
>     (select perl_sub_name, end_datetime from flow_step_events_view where
> sqf_id = sr.sqf_id order by 2 limit 1) fse
>   where sr.userid='foo';

> ERROR:  invalid reference to FROM-clause entry for table "sr"
> LINE 4: ...atetime from flow_step_events_view where sqf_id = sr.sqf_id ...
>                                                              ^
> HINT:  There is an entry for table "sr", but it cannot be referenced from
> this part of the query.

If you actually meant to access the outer "sqf_runs" RTE from the
sub-query, you need to mark it LATERAL:

select sr.sqf_id, sr.status, fse.perl_sub_name, fse.end_datetime
  from
    sqf_runs sr,
    lateral (select perl_sub_name, end_datetime from flow_step_events_view where
sqf_id = sr.sqf_id order by 2 limit 1) fse
  where sr.userid='foo';

			regards, tom lane




view thread (5+ messages)  latest in thread

Message-ID: <19947.1536268297@sss.pgh.pa.us>
Permalink:  ../19947.1536268297@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19947.1536268297@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, davegauthierpg@gmail.com
  Subject: Re: nested query problem
  In-Reply-To: <19947.1536268297@sss.pgh.pa.us>
  References: <CAMBRECCCSqSRZnBz2--ShfaP9fhkJYMVu+zktj6CEuZuT6Ovww@mail.gmail.com> <19947.1536268297@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox