Newest 'sqlalchemy' Questions - Stack Overflow

Questions tagged [sqlalchemy]

SQLAlchemy is a Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.

0
votes
0answers
20 views

SQLAlchemy Insert executemany Func

I am trying to bulk insert a list of dicts into a MySQL database via SQLAlchemy. Inside the list each dict has time and temperature. The time values are as an ISO time string. I am trying to have ...
0
votes
1answer
28 views

How can I have two tables A and B where B has all columns of A?

I am currently building a CMS. I want to have a page table and a page_revision table, where page_revision has all columns of page + rev_id + rev_parent_id. MVCE from flask_sqlalchemy import ...
0
votes
0answers
24 views

Run multiple executes/queries in a single line

I have the following code: import pandas as pd import numpy as np import MySQLdb from sqlalchemy import create_engine df = pd.read_csv('pricelist.csv') old_df = df[['date','time','old_price']] ...
0
votes
1answer
21 views

sqlalchemy foreign key could not find table

I’m making a database using sqlalchemy which consists of three classes, User, Meeting, MeetingRoom I want to create a foreign key in Meeting for the Meeting room, but for some reason it gives the ...
0
votes
0answers
19 views

SqlAlchemy XMLType DB not updating

I'm using XMLType to retrieve a XML field from a postgresql table. class XMLType(types.UserDefinedType): def get_col_spec(self): return 'XML' def bind_processor(self, dialect): def process(...
0
votes
2answers
21 views

sqlalchemy.orm.exc.UnmappedInstanceError: Class 'builtins.NoneType' is not mapped

I have 3 sqlalchemy models setup which are all one to many relationships. The User model contains many Task models and the Task model contains many Subtask models. When I execute the test_script.py I ...
-1
votes
1answer
28 views

Having an SQLite database how to iterate thru all table items only knowing table name?

I know table name, have SQLLite .db file. I want to not knowing its schema iterate thru an array of dictionaries (an item per each record containing pairs: column name : data). How to do such thing ...
0
votes
0answers
9 views

Store QuerySelectField choice in db with SQLAlchemy

I'm using QuerySelectField with SQLAlchemy and WTForms to choose an option from a database. I was want to choose the option and then store that choice or a reference to that choice in a new column but ...
0
votes
1answer
22 views

SQLalchemy-Flask: ArgumentError for one to many relationship

I am trying to use sqlalchemy to run queries for one to many relationship. I am having trouble getting my queries to run. class Quote(db.Model): id = db.Column(db.Integer, primary_key=True) ...
1
vote
2answers
25 views

Clickhouse does not return column headers

I'm trying to get some relational data from clickhouse and play with in in pandas. It works, but pd.read_sql_query returns dataframe, where column names are the values of the first row. Instead I ...
-2
votes
0answers
22 views

how can I write ordered dictionary to table as part of dynamic sql

I'm writing a python script that iterates through a list of salesforceobjects. from the list it identifies the columns then retrieves the data and converts to a data frame. When writing to the db (...
0
votes
0answers
12 views

How to force SqlAlchemy to update its columns ids when data is charged manually? [duplicate]

I have a flask app that uses SqlAlchemy and Postgresql to store anda fetch data. However, when I insert rows manually in my Postgresql database, sqlalchemy cannot identify the next available id for ...
-1
votes
0answers
20 views

Python PostgreSQL - Could not parse rfc1738 URL from string [on hold]

Since some time I'm tryin to connect to my PostrgreSQL database via Python and inserting data via pd.DataFrame.to_sql(). I'm using PostgreSQL 11 on Windows 10 and two Python packages: psycopg2, ...
0
votes
0answers
16 views

Where clause when using polymorphic_identity on base class

Base class A1 contains polymorphic_identity (along with polymorphic_on), but Query(A1) doesn't produce where clause, whereas Query(A2) (where A2 is subclass of A1 with its own polymorphic_identity) ...
-3
votes
0answers
19 views

how to get the last month data from database using sqlalchemy query

I'm trying to fetch the last 1 month data from MySQL database using sqlalchemy expressions. I don't have any idea about the query.
0
votes
0answers
7 views

pyodbc exception ProgrammingError during reboot server

Im trying to handle some errors in my application and found that only pyodbc exceptions occures, no any sqlalchemy exceptions. def f(): try: a = DB.execute('stored procedure') ...
-1
votes
1answer
20 views

pandas dataframe.to_sql turn off automatic timezone offset

Pandas DataFrame.to_sql automatically adds FixedOffsetTimezone to dataframe. My initial dataframe index doesnt have timezone: However, when I try to save dataframe and retrieve values, returned index ...
0
votes
1answer
27 views

Python + SQLAlchemy: how to update many-to-one relationship after one of relation's object field change?

I have three declarative_base models. class Region(BaseModel): id = BaseModel.column(type='integer', primary_key=True) # ... y1 = BaseModel....
0
votes
0answers
26 views

SQLAlchemy query slow with datetime type objects

I have a Flask API with SQLAlchemy interfacing a PostgreSQL database. One of the requests queries a table in a way similar to the following: SELECT * FROM mytable WHERE updated_at >= %(...
1
vote
1answer
22 views

SQLAlchemy one-to-one, store foreign key in each table?

I have a relationship that is one to one between cage codes and duns numbers. I have set up my relationship that looks like, where I store a ForeignKey on each of the respective tables. class Cage(...
0
votes
0answers
25 views

SQLAlchemy: How to use variables in a update statement

I'm trying to use a variable for a key inside a update statement, but it seems, that using variables is not allowed. There is table "disamb": +----+-----------+--------------------+-----------+------...
0
votes
0answers
17 views

Flask-Sqlalchemy create_all Table was skipped since its definition is being modified by concurrent DDL statement

I am trying to create a many to many relationship using flask-sqlalchemy. But I keep getting the error sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1684, "Table 'db'.'user' was ...
0
votes
0answers
25 views

Query Crate Database by SQLAlchemy Dialect: No more Servers available

I'd like to give it a try with crate. I first tried it by loading some twitter data and query from admin UI successfully. However, when I tried to make a query with SQLAlchemy, I've got the following ...
2
votes
1answer
29 views

Is there a way to map data from form to insert in to database without explicitly defining each variable?

I have made a really long form with the help of colander alchemy and deform. This form has 100 or so fields and currently the only way I know to add the data back to the database once form is ...
0
votes
1answer
19 views

How to print mysql database print style?

I want to print 'show databases' cmd style in python: +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys ...
0
votes
0answers
19 views

DSL like SQL in BigQuerOperator Airlfow

As a typed languages enthusiast I hate writing plain SQL queries. Unfortunately Airflow's BigQueryOperator does not provide any DSL support out of the box. So here comes my question - is it possible ...
0
votes
0answers
18 views

sqlalchemy select * subquery with alias not working

I'm dynamically generating a query for sqlalchemy: def get_objects( self, from_table, filters, select_=[], group_=[], order_=[], count=False ): if group_ and set(select_) != set(group_): ...
0
votes
0answers
14 views

Optimal way to delete an table row in SQLAlchemy when given the PK

My suspicion is that, session.query(MyClass).get(pk) is executed eagerly as opposed to a query such as session.query(MyClass).filter_by(name = 'some name') which does not get execute until the all(...
0
votes
1answer
26 views

Google Cloud SQL - Can I directly access database with SQLAlchemy - not locally

I'm trying to directly access Google Cloud SQL and create there table. I want to use as little services as possible (keep it simple), therefore I really don't want to use Cloud SDK whatever. I want ...
0
votes
1answer
19 views

Do you need to define relationship in the DB if you use ORM?

I'm pretty new to Postgres and very new to SQLAlchemy, so I apologise if this is a silly question. I've spent sometime googling this and reading the documentation on SQLAlchemy but I cant seem to ...
-1
votes
2answers
55 views

SQLAlchemy: select most recent row for all ids in a single table with composite primary key

I want to do this but in SQLAlchemy. The only difference is that rather than only being able to get the most recent record, I want to be able to get the most recent record before a given timestamp. As ...
0
votes
0answers
13 views

Snowflake + sqlalchemy autoincrement failure

I'm getting the error: sqlalchemy.exc.ArgumentError: Column type DECIMAL(38, 0) on column 'id' is not compatible with autoincrement=True When using the official example on the Snowflake website (...
0
votes
0answers
31 views

How to Update column in database but depend on a conditions and and other columns by using query

I want to create a query but depends on a condition and on other columns.... So I'll discuss in deep...... Now I create a simple Update query that's updates some columns but it's not what I need ...
0
votes
1answer
21 views

How to export from sql database an xlsx file with multiple sheet and exporting columns using python

I want to export xlsx file with multiple sheets from sql database by using queries Now I have created a three queries every query have a SELECT order for some specific data all I need now I want to ...
-2
votes
1answer
39 views

PRIMARY KEY must be unique

I am trying to write some data to a table in a database which I am creating. However, I am facing with an integrity error like: sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) PRIMARY KEY ...
2
votes
1answer
45 views

How can I add a custom, arbitrary option to a table in sqlalchemy?

I'm trying to create a table with sqlalchemy's declarative_base and I would like to add cockroachdb's INTERLEAVE IN PARENT option: CREATE TABLE orders ( customer INT, id INT, total ...
1
vote
1answer
30 views

Modfying ForeignKeyConstraint schema in Alembic post process

I'm using process_revision_directives to apply some post-processing of the operations generated against a reference schema. The one I'm stuck on is removing the postgres schema from the instructions, ...
-1
votes
0answers
26 views

How to connect SqlAlchemy to access multiple databases servers (from different servers)

I am trying to connect multiple tables from different schema's into one query in Python? I created individual variable for each conn under the variable called connections, but the error shows that ...
0
votes
0answers
14 views

Gino engine is not initialized

I'm trying to create a simple Restful API using aiohttp and Gino. Inside my endpoint class, I got the following: class ListEndpoint(Endpoint): def __init__(self, model): super().__init__() ...
0
votes
0answers
7 views

Multiple ForeignKey inserts

I have a relationship with a grandparent to parent, which has a 1-to-many relationship and a parent to child with a 1-to-many and also there is a grandparent to child with a 1-to-many. My models ...
0
votes
1answer
16 views

How to divide two columns in sqlalchemy

How generate this SQL, with sqlalchemy SELECT SUM(click) / SUM(impression) as my_indicator FROM stats; session.query( func.sum(table.click).label("click"), func.sum(table.impression).label("...
0
votes
0answers
15 views

sqlalchemy.exc.ProgrammingError: (mysql.connector.errors.ProgrammingError) Not all parameters were used in the SQL statement

I am trying to update mysql through dataframe by using tuple but I got stuck I don't know where's the problem is in mydata base or with my code and this is my whole code I use from sqlalchemy import ...
0
votes
0answers
14 views

How to assign Blob when using sqlalchemy with mysql-connector-python

When I use sqlalchemy using mysql-connector-python to read unicode from a blob I am getting: Error closing cursor UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9a in position 3: invalid start ...
0
votes
1answer
51 views

sqlalchemy.exc.ProgrammingError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version

I am trying to turn a pandas DataFrame into a SQL update statement and this is my problem part............... values = tuple(zip(*filtered_data[['site_code']].values.tolist()))[0] query = """ ...
0
votes
0answers
20 views

How to load pandas data frame data into sqlite and use the sqlite file in flask

I have loaded df data into my sqlite file . when i try to Automap base my sqlite tables from Flask . its not reading the file.
0
votes
0answers
16 views

How to write bytes to Blob in SQLAlchemy

I have the following table definition: class UserExtensibleData(CommonDeclarativeBase.DECLARATIVE_BASE): __tablename__ = 'user_extensible_data' id = Column(BIGINT(unsigned=True), primary_key=...
0
votes
0answers
21 views

FlaskSQLAlchemy - serialize data as a list

I have the following Track table, which aims to return a list of 'genres'. However there's no list datatype in SQAlchemy, so I am declaring 'genres' as a string: class Track(db.Model): ...
0
votes
1answer
26 views

Using session.query to read uncommitted data in SQLAlchemy

Summary I'm trying write integration tests against a series of database operations, and I want to be able to use a SQLAlchemy session as a staging environment in which to validate and rollback a ...
0
votes
0answers
10 views

SQLAlchemy inheritance with combination of types

I have an existing Flask app with SQLAlchemy, with many models. These models have many attributes, and my team and I decided to split them into many tables and some sort of inheritance. Dumb example, ...
0
votes
0answers
17 views

Is it possible to reflect a table in MSSQL server to SQLITE using sqlalchemy?

I'm trying to make a local copy of some tables from a read-only MSSQL server database in SQLite. I'm using sqlalchemy to do this, however, I don't seem to find a solution. Here is what I tried so far:...