Skip to content
Advertisement

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 …

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

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

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,

Advertisement