Postgres “missing FROM-clause entry” error on query with WITH clause

本秂侑毒 提交于 2019-11-29 01:11:09

From the fine manual:

There are two ways to modify a table using information contained in other tables in the database: using sub-selects, or specifying additional tables in the FROM clause.

So you just need a FROM clause:

WITH stops AS (
    -- ...
)
UPDATE consistent.master
SET arrest_id = stops.stop
FROM stops -- <----------------------------- You missed this
WHERE citing_jurisdiction=1
  AND stops.citation_id = consistent.master.citation_id;

The error message even says as much:

ERROR: missing FROM-clause entry for table "stops"

This can also happen if you mistype a table name. For example:

UPDATE profiles SET name = ( profile.first_name ) WHERE id = 1

Instead of profiles i incorrectly used profile !! This would work:

UPDATE profiles SET name = ( profiles.first_name ) WHERE id = 1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!