0

I am having a hard time understanding why psycopg2 has a problem with the word 'user'. I am trying to insert values into a table called user with the columns user_id, name, password. I am getting a programmingError: syntax error at or near "user". open_cursor() is a function used to open a cursor for database operations.

Here is my code:

query = """INSERT INTO user (name, password) VALUES (%s, %s);"""
data = ('psycouser', 'sha1$ba316b$52dd71da1e331247f0a7ab869e1b072210add9c1')
with open_cursor() as cursor:
    cursor.execute(query, data)
    print "Done."
1
  • 1
    Please always quote table names. Commented Nov 23, 2016 at 16:08

1 Answer 1

4

because user is a part of sql language.

try taking it in dbl quotes:

query = 'INSERT INTO "user" (name, password) VALUES (%s, %s);'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.