D
D
Deleting Account2020-05-15 18:20:59
Python
Deleting Account, 2020-05-15 18:20:59

Is it possible to pass an unknown number of values ​​to a sqllite3 query, without crutches?

Is it possible to pass an unknown number of values ​​to a sqllite3 query, without crutches?

cur.execute(
        """
        DELETE from item
        WHERE NOT name IN (?); 
        """
       (names,)
)
# вместо "?" должно подставится неизвестное количество параметров

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2020-05-15
@Andriy_Kosmenyuk

Unfortunately no. The only way:

placeholders = ", ".join(["?"] * len(names))
sql = f"DELETE FROM item WHERE NOT name IN ({placeholders})"
cur.execute(sql, names)

1
101-s, 2020-05-15
@101-s

As for sqlite, I'm not sure if it will work or not, but try
instead of (?) to make a selection (SELECT ...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question