I have trouble querying a table of > 5 million records from MS SQL Server database. I want to select all of the records, but my code seems to fail when selecting to much data into memory. This works: …but this does not work: It returns this error: I have read here that a similar problem exists when creating a
Tag: python
Python -SQL String Escape Wildcards
I tried to see if this question had been asked, which it probably has, but I couldn’t find an answer. I am querying MS SQL Server from a python script using pyodbc. I am defining a function to query …
python – how to check if table exists?
I’m using this function : def checker(name,s) MY_T = “SELECT count(*) FROM `”+session.SessionInfo.Name where EventName='”+name+”‘” I want to check if the table exists, how can I do it ? I …
sqlalchemy,creating an sqlite database if it doesn’t exist
I am trying out sqlalchemy and i am using this connection string to connect to my databases Does sqlalchemy create an sqlite database for you if one is not already present in a directory it was supposed to fetch the database file?. Answer Yes,sqlalchemy does create a database for you.I confirmed it on windows using this code
Django: Adding “NULLS LAST” to query
I would like to sort a model by using Postgresql’s “NULLS LAST” option. How could it be done? I tried something like MyModel.objects.all().extra(order_by=(‘-price’, ‘NULLS LAST’)) But I get “Cannot resolve keyword ‘NULLS LAST’ into field” Answer This functionality has been added to Django 1.11. https://docs.djangoproject.com/en/dev/releases/1.11/ Added the nulls_first and nulls_last parameters to Expression.asc() and desc() to control the ordering of
Using a WHERE ___ IN ___ statement
I’m trying to figure out how to properly use a WHERE _ IN _ statement Definition: I’m trying to do something like this: Alternatively, I’ve also tried this, which directly evaluates to the above The error I am getting is: This is giving me an error. When I do it this way, it works, but this is not recommended as
How to stop a search into a database when I already have results
I will post my code and explain after: db = sqlite3.connect(“Gene.sqlite”) cur = db.cursor() cur.execute(“SELECT * FROM Table”) for i in cur.fetchall(): if i[0] == name: print ‘
‘ ‘&…
Python SQLite how to get SQL string statement being executed
Let’s say we have a SQL statement that just needs to be completed with the parameters before getting executed against the DB. For instance: How do I get the string that is parsed and executed?, something like this: In this simple case it’s not very important, but I have other SQL Statements much more complicated, and for debugging purposes I
How to count rows with SELECT COUNT(*) with SQLAlchemy?
I’d like to know if it’s possible to generate a SELECT COUNT(*) FROM TABLE statement in SQLAlchemy without explicitly asking for it with execute(). If I use: session.query(table).count() then it …
SQLalchemy specify which index to use
Is there a way in SQLalchemy to tell the query which index to use? The reason I need this is that the SQL queries it generates use the “wrong” index – there exists an index for exactly the two fields that I have and it doesn’t use it. Thanks! Answer I think you can use with_hint() for this. e.g. Honestly,