I have a trouble when I try to automatically generate pid
CREATE TABLE players(
pID SERIAL primary key,
pName VARCHAR(90) not null
);
and here is my function
def addPlayer(name):
conn = connect()
cur = conn.cursor()
cur.execute("INSERT INTO players(pName) VALUES(%s)",name)
conn.commit()
and I call the function with
addPlayer('Vera')
I keep getting the error that
cur.execute("INSERT INTO players(pName) VALUES(%s)",name)
TypeError: not all arguments converted during string formatting
I search for hours but still confused. Can anyone help me with this? Thanks a lot!
I think you're confusing string interpolation with query variables.
String interpolation:
Query variables:
So changing your comma to a
%
would pass the variable into the string and would work, but the other way sanitises the input, so you should use the second example as is.