2013-04-07 22 views
6

Errore di mancata corrispondenza dell'operatore durante l'esecuzione di una query semplice. Che cosa causa questo?Errore PostgreSQL: operatore inesistente: nome = intero

 
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. 

definizione Tabella:

 
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 

risposta

7

Secondo il manuale, USER è una parola chiave riservata. È necessario citarlo per evitare l'errore di sintassi.

SELECT * FROM registrants WHERE "user" = 1 

PostgreSQL Reserved Keyword List

Se avete tempo di modificare il database, modificare il nome della colonna di uno che non è una parola chiave riservata. Questo ti aiuterà a evitare futuri mal di testa.

+3

@ user2254435: non utilizzare le parole riservate come identificatori per iniziare. –

+0

Grazie per la rapida risposta. Questo è da una grande applicazione esistente e non è così facile da cambiare. – DevR

Problemi correlati