1

I use python to connect to my postgresql database. I parse a XML fill to populate my base, so I have an array[] of values for one line to insert. I have something like this:

cur.execute("""INSERT INTO ACTIVITYDESC VALUES (%s,%s,%s,%s,%s)""",(value[0],value[1],value[2],value[3],value[4]))

There is a way to make this more simple like: ?

cur.execute("""INSERT INTO ACTIVITYDESC VALUES (%s)""",(value)) 

Thank for your help

3

1 Answer 1

0

Turn the list into a tuple:

t = tuple(value)
cur.execute("""INSERT INTO ACTIVITYDESC VALUES %s""",(t,)) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.