2013-04-07 7 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

संबंधित मुद्दे