Question

  Select distinct A.col1, B.col2, col3
   from A inner join B on A.id = B.id
   and B.id in 

       (select distinct col2 from B where ..... )

PostgreSQL's plpgsql parser does not like the unqualified "col2" in the parenthetic subquery. Since there's only one table mentioned in the subquery, isn't the parser manufacturing an ambiguity where there is none?

Was it helpful?

Solution

An SQL query like you display would just work.

Since you mention plpgsql, my shot in the dark is that you are only showing fragments from what is actually a plpgsql function and you run into naming conflicts with function parameters, which are visible anywhere in the function body (except dynamic SQL).

OTHER TIPS

No. Outer query columns are available in the subquery too, otherwise you couldn't bind the inner and outer queries together. It's an easy thing to forget and can catch you out if you're not expecting it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top