Reputation: 123
I'm new to Python. I'm executing this very basic query:
connection = psycopg2.connect("dbname='test' host='localhost' user='admin' password='pass' port='9100'")
cur = connection.cursor()
cur.execute("""SELECT id FROM pages WEHERE uri = %(uri)s""", {'uri': uri})
row = cur.fetchall()
and keep getting this error:
<class 'psycopg2.ProgrammingError'>
('syntax error at or near "uri"\nLINE 1: SELECT id FROM pages WEHERE uri = \'http://example.com/index.php...\n ^\n',)
uri
is a string and has the value http://example.com/index.php
Could you please help me?? This is making me crazy
Upvotes: 0
Views: 4702
Reputation: 8335
It should be:
cur.execute("""SELECT id FROM pages WHERE uri = %(uri)s""", {'uri': uri})
That is, it should be where
instead of wehere
. Since there is no function like wehere
in SQL, the syntax error is thrown.
The error itself is self-explanatory. Next time, read the error message closely.
Upvotes: 2