2013-04-07 111 views
6

単純なクエリを実行すると演算子の不一致エラーが発生します。この原因は何ですか?PostgreSQLエラー:演算子が存在しません:名前=整数

 
dev_db=# `select * from registrants where user=1;` 
ERROR: operator does not exist: name = integer 
LINE 1: select * from registrants where user=1; 
              ^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 

テーブル定義:

 
dev_db=# \d+ registrants 
           Table "public.registrants" 
    Column |   Type   |  Modifiers  | Storage | Description 
--------------+--------------------------+--------------------+----------+------------- 
user   | integer     | not null   | plain | 
degree  | text      |     | extended | 
title  | text      |     | extended | 
organization | text      |     | extended | 
address  | text      |     | extended | 
city   | text      |     | extended | 

Indexes: 
    "registrants_pkey" PRIMARY KEY, btree ("user") 
Foreign-key constraints: 
    "registrants_country_fkey" FOREIGN KEY (country) REFERENCES countries(id) 
    "registrants_user_fkey" FOREIGN KEY ("user") REFERENCES users(id) 
Referenced by: 
    TABLE "class_evaluations" CONSTRAINT "class_evaluations_registrant_fkey" FOREIGN KEY (registrant) REFERENCES registrants("user") 

Triggers: 
    archive_registrants BEFORE DELETE OR UPDATE ON registrants FOR EACH ROW EXECUTE PROCEDURE archive_reg_table() 
Has OIDs: no 

答えて

7

マニュアルによれば、USERは予約キーワードです。構文エラーを避けるには、引用符で囲む必要があります。

SELECT * FROM registrants WHERE "user" = 1 

PostgreSQL Reserved Keyword List

データベースを変更するための時間を持っている場合は、予約済みのキーワードではありませんどちらに列名を変更します。これは将来の頭痛を避けるのに役立ちます。

+3

@ user2254435:予約語を識別子として使用しないでください。 –

+0

迅速な対応をありがとうございます。これは、既存の大規模なアプリケーションからのものであり、簡単に変更することはできません。 – DevR

関連する問題