postgres column alias problem

后端 未结 4 737
余生分开走
余生分开走 2020-12-06 11:29

As a newbie to Postgresql (I\'m moving over because I\'m moving my site to heroku who only support it, I\'m having to refactor some of my queries and code. Here\'s a problem

4条回答
  •  生来不讨喜
    2020-12-06 11:35

    You have:

    order by l2.geopoint_id, l_user_id = l2.user_id desc
    

    in your query. That's illegal syntax. Remove the = l2.user_id part (move it to where if that's one of the join conditions) and it should work.

    Update Below select (with = l2.user_id removed) should work just fine. I've tested it (with different table / column names, obviously) on Postgres 8.3

    select distinct 
           l2.*, 
           l.user_id as l_user_id, 
           l.geopoint_id as l_geopoint_id 
      from locations l 
      left join locations l2 on l.geopoint_id = l2.geopoint_id 
     where l.user_id = 8 
     order by l2.geopoint_id, l_user_id desc
    

提交回复
热议问题