Category : sqlalchemy

I have created a refresh button that updates the portfolio table with the sum of products table: #refresh portfolio stats @app.route(‘/refresh’, methods = [‘GET’,’POST’]) def refresh(): if request.method == ‘POST’: database = "data.sqlite" connection = sql.connect(database) query = ”’ UPDATE portfolio_table SET portfolio_cost_total = (SELECT SUM(product_cost_total) FROM product_table) WHERE portfolio_table.portfolio_id = 1 ”’ cursor = ..

Read more

I want to dynamically derive columns with the server_default set to Computed(…). The statement going into Computed(…) has to be derived from other columns, and therefore needs to have access to the class after the relationships have been mapped: from uuid import uuid4 from sqlalchemy import func, Computed, ForeignKey, Column from sqlalchemy.orm import relationship from ..

Read more

Background, Objective Given an existing database, generate sample data for testing which: Should consist of actual rows, Should allow queries across related tables using joins across any depth of hierarchy (e.g. parent/child/grandchild… etc) Current approach I have the database reflected, and am using SLQAlchemy’s inspect to find all related tables. Iterating this method n times ..

Read more

I have the following query executed using pandas’ read_sql method that works great when querying against a MySQL db: sql = "SELECT * FROM semantic_groups sg join semantic_types st on sg.tui = st.tui where group_name in ({})".format(‘, ‘.join([‘%s’ for _ in semtypes])) stypes = pd.read_sql(sql, params=[semtypes], con=engine) However, when I run this against the same ..

Read more