Questions tagged [sqlalchemy]
SQLAlchemy is a Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
20,636
questions
0
votes
0
answers
13
views
Python SQLAlchemy raw query count + results
I have the following query and i need to add it the func.count().over().label('full_count') like described by sayap in this post, but i absolutly don't know how :(.
Here is my query :
result_rows = ...
-2
votes
1
answer
20
views
data in flask sqlalchemy database gets deleted by itself after a few hours [duplicate]
I created a web blog with flask and sql alchemy database and I hosted it using heroku services, it was good at first, but after a few hours the data stored on the web such as user data and blogs was ...
0
votes
0
answers
12
views
SQLAlcehmy shows error when trying to add an item
I am trying to put 1 item into a column called Item. The following code generates the error you see at the bottom. I wish I could explain more, but this is a pretty simple request I am trying and I ...
-1
votes
0
answers
20
views
Flask - Create multible Users with multible functionalities in a website
I have a single login page and 3 database classes for (admin, Doctor, patient). I want whoever login to be redirected to a page with different functionalities based on who they are.
the problem is ...
1
vote
2
answers
25
views
SQLAlchemy stored procedure is not working in Postgres
I have a table called city in PostgreSQL
CREATE TABLE CITY (
CITYID serial PRIMARY KEY,
CNAME VARCHAR (50) UNIQUE NOT NULL,
STATE VARCHAR (50) NOT NULL
);
When I use simple select with ...
0
votes
0
answers
8
views
Sqlalchemy join and filter by pre-defined function
Let's say I have 2 models User and Order.
Relationship:
User has many Orders, and another method to determine if the order is refund.
def is_refund(order: Order) -> bool:
# return True or False
...
0
votes
0
answers
10
views
How to count relations in SQLALCHEMY
I have two tables and I'm trying to get the number of posts in a Thread, filtering by the thread's id
class Threads(db.Model):
__tablename__ = 'threads'
id = db.Column(db.Integer, primary_key=...
1
vote
1
answer
24
views
How do i delete a post in flask
I can't able to delete a individual post in flask here is my code.i am learning and i can't understand this error.Because i queried the individual post by id then i deleted it then i also did db....
0
votes
0
answers
6
views
Error sqlalchemy.orm.exc.DetachedInstanceError: Instance <User at 0x102827910> is not bound to a Session
I really want to understand this problem:
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import as_declarative, declared_attr
from typing import Any
@as_declarative()
...
0
votes
0
answers
14
views
Distributed Query in sqlalchemy
Consider there are two database "A" and "B" which are not having different sqlalchemy dialects. Database "A" has "product" table and database "B" has &...
0
votes
0
answers
15
views
Flask Post Image Binding Error Parameter 2
I keep getting this error when I run my Python FLASK web application when trying to create an Image Post for my PostForm
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter ...
0
votes
0
answers
29
views
How to load a dataframe to postgresql 14
i have tried to load my dataframe to postgresql and especially to the server postgresql 14( i have 2 servers postgresql 9.3 running on port 5434 , and the other one is postgresql 14 running on port ...
0
votes
0
answers
16
views
One to many relationship with assortment of models in Flask-SQLAlchemy
The structure I'd like to create:
model Lesson:
column Tasks(many to many)
model Task_video:
....
model Task_test:
....
model Task_audio:
....
Each Task_ is quite different from others, so I'd ...
0
votes
0
answers
8
views
sqlalchemy.exc.AmbiguousForeignKeysError While using the Mapping Class Inheritance Hierarchies
Background
I am working on an app and on the backend part, I am using Sqlalchemy with ORM to create my database.
My model has 8 classes or tables and uses the object-oriented paradigm for the users ...
-1
votes
0
answers
24
views
How do i create a FULLTEXT index in sqlalchemy/mariadb in python?
I'm trying to add a FULLTEXT index to a pre-existing model. Im not entirely sure what im doing, I currently have this -
class Article(TableBase, CreatedMixin, HistoryMixin):
name = Column(String(...
0
votes
1
answer
17
views
Check if dataframe satisfies database table column definitions
Is there a way to check if pandas dataframe satisfies definitions of table comlumns in a database? I want to do this inspection before using pd.to_sql() funcion in order to avoid errors and exceptions....
0
votes
0
answers
20
views
(Hack to get Auth to work) ERROR: default: Authentication failed: password is incorrect or there is no user with such name (clickhouse sqlalchemy)
Issue: When using Sqlalchemy(Python/Pandas Dataframe) to connect to Clickhouse DB, below error occurs when attempting to authenticate credentials.
Error: default: Authentication failed: password is ...
0
votes
1
answer
26
views
SQLAlchemy performance of SELECT is 2x slower than a raw connection to Oracle
I am timing get_core and get_orm against get_raw with the following results:
get_raw got 10000 rows, time: 0:00:04.201974
get_core got 10000 rows, time: 0:00:08.048311
get_orm got 10000 rows, time: 0:...
0
votes
1
answer
38
views
SqlAlchemy + fastApi trying to join many - to - many tables
1st table "release_name":
|code|name|
|:---|:--:|
|1---|SOME|
|2---|ANY |
...
2nd table "release_value":
|code|name|
|:---|:--:|
|1---|SOME|
|2---|ANY |
...
3rd Is a table to make ...
0
votes
0
answers
16
views
Unable to get an id from the database after doing insert using sqlalchemy
Assuming this model:
class Pipeline(Base):
__tablename__ = "pipeline"
pipeline_id = Column(String, primary_key=True)
pipeline_version_id = Column(Integer, primary_key=True, ...
0
votes
1
answer
24
views
'Post' object has no attribute '_sa_instance_state'
It is an API for site https://asperitas.now.sh
I'm trying to get all posts from my database like so:
(link for gh: https://github.com/Jonny-programmer/tgym_api)
def get_all(self):
print(&...
0
votes
0
answers
6
views
Connect to hive with sqlalchemy odbc.ini file
I'd like to connect to Hive using sqlalchemy and odbc.ini file
I have a odbc.ini file that looks like
[Hive]
Description = ODBC Hive connection to Hadoop cluster
Driver = /opt/cloudera/hiveodbc/lib/64/...
0
votes
0
answers
11
views
How can I add selected columns to a select statement in sqlalchemy?
If I have the following models:
Base = declarative_base()
class Customer(Base):
__tablename__ = 'Customers'
Id = Column(Integer, primary_key=True)
Name = Column(String(255))
class ...
0
votes
0
answers
22
views
SQLAlchemy many to many relationship not working
Hey guys Im trying to set up 2 models with a many to many relationship, basically the 1st model is a "trainer" model and the 2nd model is a "matches" model and the match model will ...
0
votes
0
answers
11
views
Making a one-to-one join to an inherited table via the primary key in SQLAlchemy
I have a MySQL table 'users' with the following fields
users
----
id: int (pk)
name: string
email: string
can_edit_records: bool
can_delete_records: bool
And I want to represent that as two separate ...
0
votes
0
answers
9
views
sqlalchemy listens_for happening before table is fully created
I have noticed the listens_for decorator for sqlalchemy starts before the table is fully created, at least in my code. What should I be doing in order to make sure it starts after. Let me know if you ...
1
vote
1
answer
21
views
How to upsert in mySQL so it will work with sqlite3?
I need to test a python flask app that uses mySQL to run its' queries using sqlalchemy, with sqlite3.
I've encountered an exception when trying to test an upsert function using an ON DUPLICATE clause:
...
-2
votes
0
answers
24
views
Calculate the number of engaged users within the last 20 days prior to a date
I need to calculate the number of engaged users within the last 20 days prior to a column called churning, which is a timestamp. There are two tables, one is called accounts:
churn_date ...
0
votes
0
answers
10
views
Sqlalchemy upsert failing despite autoflush is turned off
I am using falcon web framework and sqlalchemy ORM. To connect to the DB, I am using a scoped session that is created on the request. While creating, the field autoflush is set to False. But on upsert,...
1
vote
0
answers
18
views
How to transfer a Pandas dataframe to a database matching foreign keys using pd.to_sql and SQLAlchemy functionality?
I want to append data to a database table that has foreign keys linking to another table but I haven’t found a way to use SQLAlchemy functionality to match the existing foreign keys.
Let’s say I have ...
0
votes
0
answers
5
views
celery with kombu fails to start: Table queue_id_sequence does not exists
Celery with kombu fails to start, throwing the following error
2022-05-24 19:19:28,546: CRITICAL/MainProcess] Unrecoverable error: StatementError('(sqlalchemy.exc.ProgrammingError) (pymysql.err....
0
votes
0
answers
7
views
MySQL Lock Timeout on Insert (with no dependencies)
I have a MySql Table with the following structure:
Field type Key Extra
id int(11) PRI auto_increment
shop_id varchar MUL
target_count int(11)
I only write ...
0
votes
1
answer
23
views
I'm dealing with error "TypeError: Object of type Row is not JSON serializable" FastApi + sqlalchemi
I have "many to many" relationship table. After fetching I'm trying sending result to a client but keep getting "TypeError: Object of type Row is not JSON serializable".
I'm able ...
0
votes
0
answers
5
views
Percona error reading communication packets with python
I have the same issue while trying to connect to mysql(percona) container upped with docker-compose.
I have this simple code
import sqlalchemy
engine = sqlalchemy.create_engine(
f'mysql+...
1
vote
1
answer
40
views
Iterating over 2 lists in SQL execution using SQL Alchemy
I currently have this query:
for table_name in bmds_stage_tables:
get_updated_tables = conn.execute(
f"""
DECLARE @csId INT = ?
...
0
votes
0
answers
21
views
One to one relation sqlalchemy
I am creating a TODO list. Each user has to have only one TODO list. ( I assume one to one model ).
If I set default value of todolist is None for each user, then create a todolist - it won't link it ...
0
votes
0
answers
30
views
sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) Cannot operate on a closed database
I simplified my code so it can be reproduced. The "select empty template file" popup can be any file. I did contact the author of uszipcode and he is super nice and told me that the way I'm ...
-2
votes
0
answers
22
views
Flask Module not Found after installing Flask
I am faced with a problem of running flask. It has been successfully installed yet when I try to import on command line it says Flask Module Not Found
0
votes
0
answers
11
views
Random choice for random question query (ORM)
I have two tables: Question and QuestionChoice, the latter has a 'question_id' foreign key. There are many questions, each with several question choices.
I want a query that returns a list of N ...
0
votes
1
answer
29
views
How to convert SQL with WHERE clause as subquery to SQLAlchemy
class Post(Base):
__tablename__ = "posts"
id = Column(Integer, primary_key=True, index=True)
title = Column(String(50))
posts_to_tags = relationship(
"...
0
votes
0
answers
27
views
get_table_names() returns an empty list even though tables do exist
I'm running something relatively simple
connection_url = 'mssql+pyodbc://server.local/DB?driver=SQL+Server&trusted_connection=yes'
eng = sa.create_engine(connection_url)
insp = sa.inspect(eng)
len(...
0
votes
1
answer
64
views
Reading an SQL query into a Dask DataFrame
I'm trying create a function that takes an SQL SELECT query as a parameter and use dask to read its results into a dask DataFrame using the dask.read_sql_query function. I am new to dask and to ...
0
votes
1
answer
27
views
joinedload and load_only but with filtering
I have two models with a simple FK relationship, Stock and Restriction (Restriction.stock_id FK to Stock).
class Restriction(Model):
__tablename__ = "restrictions"
id = db.Column(db....
1
vote
1
answer
23
views
How to execute a sqlalchecmy TextClause statement with a sqlite3 connection cursor?
I have a python flask app which primarily uses sqlalchemy to execute all of it's mySQL queries and I need to write tests for it using a local database and behave.
After a brief research, the database ...
0
votes
0
answers
7
views
Execute SQL query read the response and from response read property values and insert those values into email template
For Example:(Use Python)
email_template ="""
Client Nmae: {{clientName}}
Client ID : {{ clientid }}
"""
1.Once i execute the SQL query the resonse i am ...
1
vote
1
answer
30
views
multiple database backends per session along with db.execute when using sqlaclhemy
I have this database connection in a fast API app.
I am using multiple binds to the same session, I followed the documentation here:
Query the db:
method1: working
db.query(Model).all()
method2: not ...
0
votes
0
answers
16
views
Save Python dictionary including sets to a JSONB column in SqlAlchemy
Using Python and SqlAlchemy, I'm getting the following exception when trying to save a Python dictionary to a JSONB column using SqlAlchemy:
sqlalchemy.exc.StatementError: (builtins.TypeError) Object ...
0
votes
1
answer
20
views
How to update specific row in Sqlalchemy ORM for a non unique primary key
Am attempting to use SQLAlchemy ORM to update a particular row in the database but because I want to keep history of everything that has ever happened to the row I want to version off the record and ...
0
votes
0
answers
13
views
Convenience of relationships, where relationships not possible?
I have three objects (Leads, MarketingMails, WebformSubmissions). I'd like to query for objects related to each other through a join. Example:
class MarketingMail(db.Model):
...
0
votes
0
answers
22
views
sqlite3.ProgrammingError from uszipcode package and use tkinter to get the filename
I'm using this to obtain lat & lon from zipcode and try to get the distance between two zipcode.
I got the following error ( I got all the results I want but still want to figure out what's wrong ...