2017-06-30 9 views
0

値を返すようにクエリを取得しようとしていますが、私はNoneを取得します。PosgresqlのWhere句を追加するにはpsycopg2 Pyyhon execute文

 selectstatement = "SELECT * FROM customer Where (('ID' =" +"%s" 
     data = 12345 

     cursor.execute(selectstatement, (data,)) 
     records = cursor.fetchone() 
     print(records[0]) 

は今、私はそれがテーブル内に存在することがわかっているが、私はエラーを取得:私はこれを行う場合は

Traceback (most recent call last): 
    File "C:\Users\yfevrier\Desktop\EnterRegister.py", line 86, in <module> 
    StartClean() 
    File "C:\Users\yfevrier\Desktop\EnterRegister.py", line 28, in StartClean 
    Analyze(DataReader) 
    File "C:\Users\yfevrier\Desktop\EnterRegister.py", line 66, in Analyze 
    print(records[0]) 
TypeError: 'NoneType' object is not subscriptable 

を:

selectstatement = "SELECT * FROM customer 


cursor.execute(selectstatement) 
records = cursor.fetchall() 

私はすべての結果を得るが、私は見つけるカントリソースを使用してwhere句を完全に指定します。

+0

は、完全なエラーメッセージを表示します。 –

+0

@ClodoaldoNeto テーブルが情報を持っているのだが、私はレコードを取得できないようだ。私の実行クエリが間違っていると信じている。 – Blue

答えて

0

文字列IDを渡された値と比較しています。 ID列名が大文字で作成され、二重引用符に包まれたならば、必ず二重引用符を使用する必要がある

selectstatement = "SELECT * FROM customer Where ID = %s" 

:しかしこれは正しい方法である

selectstatement = '''SELECT * FROM customer Where "ID" = %s''' 
+0

ありがとう!私はPythonを知っていた!あなたは私を大きく助けました – Blue

関連する問題