作为 Postgresql 的新手(我要搬家是因为我将我的网站移动到只支持它的 heroku,我不得不重构我的一些查询和代码。这是一个我不太明白的问题和:
PGError: ERROR: column "l_user_id" does not exist
LINE 1: ...t_id where l.user_id = 8 order by l2.geopoint_id, l_user_id ...
^
...询问:
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 = l2.user_id desc
添加了子句“l.user_id as l_user_id, l.geopoint_id as l_geopoint_id”,因为显然 postgres 不喜欢未选择字段的 order 子句。但是我现在得到的错误使它看起来我也没有得到别名。有postgres经验的人看到这个问题吗?
我可能会遇到很多这样的问题——查询在 mySql 中运行良好......