Skip to content
Advertisement

Tag: sqlalchemy

How to union two counts queries in SQLAlchemy?

I have two queries and the only difference between then is that one is counting the success status and the other failure status. Is there a way to get this result in just one query? I’m using SQLALchemy to do the queries. Answer You can use conditions on Count, your query will look like:

Case in Sqlalchemy hybrid_property / expression error

I want to use expressions is ORM queries like this. Profile.query.filter(Profile.complete).all() Where complete is a calculated field Sqlalchemy docs shows the below So i’ve attempted to copy it with the following. But the output sql query is as below – the case isn’t compared agaisnt anything. So my output is all profiles, instead of only complete ones. What am I

Can’t connect Sqlalchemy with pyodbc to SQL Server 2000

I followed this website by installing After install I try this code and it worked, it print all records from table2 However, I want to use SQLAlchemy with pyodbc and it does not work ProgrammingError: (pyodbc.ProgrammingError) (‘42000′, “[42000] [FreeTDS][SQL Server]’schema_name’ is not a recognized function name. (195) (SQLExecDirectW)”) [SQL: SELECT schema_name()] (Background on this error at: https://sqlalche.me/e/14/f405) How can I

SQLAlchemy group by day in timestamp column

I have an ORM (Model) defined in SQLAlchemy as below: I’m planning to get the sum of all views in each day and tried to group the results based on their end_to. I have used the following query in sqlalchemy: But this query throws this error: I am using the timestamp in my model and I don’t plan to change

Querying JSON in POSTGRESQL returns NONE everytime

jsonb column text_results contains values in the following form : {‘Name’ : ‘john doe’ , ‘id’ : ‘123’} On querying Select text_results->>’Name’ as Name from user_master or Select json_extract_path_text(text_results::json,’Name’) as name from user_master it always return None without any error even though values are present. Need help with rectifying the error or any other way of extracting values from json

Why doesn’t SQLite appear to lock my table / row?

I’m tinkering with an in-memory sqlite database, trying to wrap my head around concurrency. Here’s an example using SQLAlchemy OUTPUT Here, I use two connections to write data to the same record. I would expect the output to be “A112”, because I thought the first connection would have a lock on the record until it COMMITs, but to my surprise

Advertisement