Search Postgresql Archives

Re: nested query problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Gauthier <davegauthierpg@xxxxxxxxx> 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





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux