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

前端 未结 2 928
-上瘾入骨i
-上瘾入骨i 2020-12-15 17:01

I am trying to use this query in Postgres 9.1.3:

WITH stops AS (
    SELECT citation_id,
           rank() OVER (ORDER BY offense_timestamp,
                         


        
相关标签:
2条回答
  • 2020-12-15 17:49

    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"

    0 讨论(0)
  • 2020-12-15 17:52

    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
    
    0 讨论(0)
提交回复
热议问题