Pastebin
Paste #592: No description
< previous paste - next paste>
Pasted by Anonymous Coward
cursor.execute("""INSERT INTO customer(id, name) VALUES( %s, %s)""" % (id, name)) Gives: Connecting... Customer ID: 100001 Customer name: Hest Inc. Creating new customer(id=100001; name='Hest Inc.') Traceback (most recent call last): File "soho-create-customer.py", line 23, in <module> VALUES( %s, %s)""" % (id, name)) psycopg2.ProgrammingError: syntax error at or near "Inc" LINE 2: VALUES( 100001, Hest Inc.) ------- documentation: Adaptation of Python values to SQL types psycopg2 casts Python variables to SQL literals by type. Standard Python types are already adapted to the proper SQL literal. Example: the Python function: curs.execute("""INSERT INTO atable (anint, adate, astring) VALUES (%s, %s, %s)""", (10, datetime.date(2005, 11, 18), "O'Reilly")) is converted into the SQL command: INSERT INTO atable (anint, adate, astring) VALUES (10, '2005-11-18', 'O''Reilly');
New Paste
Go to most recent paste.