0

I'm using python cx_oracle , When I try to insert variables into sql:

cursor.executemany(f"INSERT INTO table ({columns}) VALUES ({placeholders })",t)

it returns:

  File "eula_db.py", line 77
    cursor.executemany(f"INSERT INTO table ({columns}) VALUES ({placeholders })",t)
                                                                                       ^
SyntaxError: invalid syntax
William
  • 3,724
  • 9
  • 43
  • 76

1 Answers1

1

Use Python 3.6

With t.py containing:

columns = 'abc'
placeholders = ':b'
s = f"INSERT INTO EULA_STG_DATA ({columns}) VALUES ({placeholders })"
print(s)

the behavior depends on the Python version:

$ python --version
Python 2.7.16
$ python t.py 
  File "/Users/cjones/py/so15.py", line 3
    s = f"INSERT INTO EULA_STG_DATA ({columns}) VALUES ({placeholders })"
                                                                        ^
SyntaxError: invalid syntax

With a newer Python:

$ python --version
Python 3.9.1
$ python t.py 
INSERT INTO EULA_STG_DATA (abc) VALUES (:b)
Christopher Jones
  • 9,449
  • 3
  • 24
  • 48