문제

Postgres 9.1.3에서 이 쿼리를 사용하려고 합니다.

WITH stops AS (
    SELECT citation_id,
           rank() OVER (ORDER BY offense_timestamp,
                     defendant_dl,
                     offense_street_number,
                     offense_street_name) AS stop
    FROM   consistent.master
    WHERE  citing_jurisdiction=1
)

UPDATE consistent.master
SET arrest_id = stops.stop
WHERE citing_jurisdiction=1
  AND stops.citation_id = consistent.master.citation_id;

다음 오류가 발생합니다.

ERROR:  missing FROM-clause entry for table "stops"
LINE 12: SET arrest_id = stops.stop
                         ^

********** Error **********

ERROR: missing FROM-clause entry for table "stops"
SQL state: 42P01
Character: 280

정말 혼란스러워요.WITH 절은 Postgres 문서에 따라 올바른 것으로 나타납니다.WITH 절에서 별도로 쿼리를 실행하면 올바른 결과를 얻습니다.

다른 팁

테이블 이름을 잘못 입력한 경우에도 이런 일이 발생할 수 있습니다.예를 들어:

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

대신에 profiles 내가 잘못 사용했어 profile !!이것은 작동합니다:

UPDATE profiles SET name = ( profiles.first_name ) WHERE id = 1
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top