Linked Questions

-4 votes
1 answer
7k views

How to print the ACTUAL SQLAlchemy query to troubleshoot: SQLAlchemy filter statement replaces filter critieria with %(column_name_1)s [duplicate]

I have a SQLAlchemy query that looks like this: query = db.session.query( Place.name, Place.population, ).filter(Place.population==8000) But when I print the query, it comes out as: SELECT ...
sunday_funday's user avatar
0 votes
1 answer
666 views

Printing the SQLAlchemy Query in Python [duplicate]

I need to know the way of getting the SQLAlchemy query printed with values. I can be able to print the query which is getting processed, But it is not showing the values instead it just showing the ...
Murali's user avatar
  • 1,114
1 vote
0 answers
179 views

Sqlalchemy print SQL query to database [duplicate]

I have a query like this: res = db.query("value").from_statement( text("SELECT f.val AS value " "FROM facts f, persons p" "WHERE " "f.person_id=:region || p.id::text") ...
PepperoniPizza's user avatar
0 votes
0 answers
107 views

SQLAlchemy: print the actual raw SQL query alongside its bind params [duplicate]

well aware that something similar has been already discussed in detail (here), nevertheless my question concerns those cases in which a raw SQL must be executed. Given the following example from ...
Pankus's user avatar
  • 1,477
0 votes
0 answers
67 views

How can I write a distinct on query in sqlalchemy? [duplicate]

I have an SQL query I'm trying to translate to sqlalchemy but it's not the same. Here's the query: select distinct on (uid) uid, id, amount, type, due_date from events where status = 'pending' and ...
ninesalt's user avatar
  • 4,392
13 votes
4 answers
33k views

Insert a list of dictionary using sqlalchemy efficiently

I have a list containing dictionaries as elements. All the dictionaries confronts to my schema, is there a simple or efficient way to insert these details in db with sqlalchemy? my list is below [{...
Ishan Bhatt's user avatar
  • 10.4k
15 votes
3 answers
13k views

Sqlalchemy - how to get raw sql from insert(), update() statements with binded params?

Example: from sqlalchemy.dialects import mysql from sqlalchemy import Integer, Column, update, insert from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Test(...
tk111's user avatar
  • 161
14 votes
2 answers
7k views

Datetime filtering with SQLAlchemy isn't working

Basically, I need to build a function that will filter a query according to given dates and return a new query. I'm new to SQLAlchemy, I looked up similar questions but I still got the same error: `...
Felipe Muniz's user avatar
13 votes
1 answer
5k views

SQLAlchemy requires query to be aliased yet that alias is not used in the generated SQL

I have a simple model class that represents a battle between two characters: class WaifuPickBattle(db.Model): """Table which represents a where one girl is chosen as a waifu.""" ...
HennyH's user avatar
  • 7,974
2 votes
2 answers
4k views

sqlalchemy FOR UPDATE NOWAIT

The documentation for sqlalchemy says that you can specify "FOR UPDATE NOWAIT" in PostgreSQL 8.1 upwards using Query.with_lockmode('update_nowait'). Does anyone know how to get it to add the FOR ...
tponthieux's user avatar
  • 1,552
2 votes
1 answer
7k views

SQLAlchemy: how to print real query from db session

There are other questions similar to mine but none of them can help me find a solution. I have a query that is db.session.query(cls).filter_by(id=id).delete() and I'm trying to print the exact query. ...
Steve's user avatar
  • 297
4 votes
2 answers
2k views

Partial UUID match in Python/SQLAlchemy

Trying to develop a script in Python/SQLAlchemy that can take a substring and partially match it against a UUID. For example: the string "d78d" would match UUID('3f522efe-d78d-4081-99a5-...
rook's user avatar
  • 41
3 votes
1 answer
2k views

In SQLAlchemy how do I preview SQL statements before committing for debugging purposes?

I want to see the SQL code instead of doing an actual db.commit(). This is for a one-off database population script that I want to verify is working as intended before actually making the changes.
wuxiekeji's user avatar
  • 1,902
2 votes
0 answers
3k views

Generate sqlalchemy queries with substituted parameters

I have a new app that already uses sqlalchemy, so has sqlalchemy table definitions already. I'd like to use sqlalchemy to generate an SQL script to migrate data from an old app. So I want to ...
Croad Langshan's user avatar
2 votes
1 answer
3k views

How can I print actual query generated by SQLAlchemy?

I'm trying to log all SQLAlchemy queries to the console while parsing the query and filling in the parameters (e.g. translating :param_1 to 123). I managed to find this answer on SO that does just ...
onetwothree's user avatar

15 30 50 per page