Skip to content
Advertisement

Tag: python

Aggregating save()s in Django?

I’m using Django with an sqlite backend, and write performance is a problem. I may graduate to a “proper” db at some stage, but for the moment I’m stuck with sqlite. I think that my write performance problems are probably related to the fact that I’m creating a large number of rows, and presumably each time I save() one it’s

Python: Number of rows affected by cursor.execute(“SELECT …)

How can I access the number of rows affected by: Answer Try using fetchone: result will hold a tuple with one element, the value of COUNT(*). So to find the number of rows: Or, if you’d rather do it in one fell swoop: PS. It’s also good practice to use parametrized arguments whenever possible, because it can automatically quote arguments

How to use variables in SQL statement in Python?

I have the following Python code: where var1 is an integer, var2 and var3 are strings. How can I write the variable names without Python including them as part of the query text? Answer Note that the parameters are passed as a tuple. The database API does proper escaping and quoting of variables. Be careful not to use the string

How to use “AND” in a Django filter?

How do I create an “AND” filter to retrieve objects in Django? e.g I would like to retrieve a row which has a combination of two words in a single field. For example the following SQL query does exactly that when I run it on mysql database: How do you accomplish this in Django using filters? Answer (update: this answer

Advertisement