1
vote
0answers
15 views

How to add a where clause to a statement with a known column name in SQLAlchemy 0.9?

There is a set of tables, all of which have a column with a determined name, say 'ColA'. I'm trying to write a function which will a attach a specific where clause to a SqlAlchemy statement (Insert, ...
0
votes
0answers
13 views

SqlAlchemy+Tornado: can't reconnect until invalid transaction is rolled back

i'm building a webapp with tornado+sqlalchemy and absolutely random i got this error File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1024, in _handle_dbapi_exception ...
0
votes
0answers
10 views

Is the use of Parent and Child classes in SQLAlchemy documentation a red herring?

Immediately upon reading about relationship configuration in the SQLAlchemy docs, it's easy to wonder why Child and Parent classes were chosen for the examples. This usually implies subclassing, but ...
0
votes
0answers
32 views

Flask + sqlalchemy - NameError: global name 'string is not defined

Cannot figure out why this exception is being thrown only sometimes - maybe one in five attempts. I have a simple API that accepts a file, stores it, and logs some metadata in a postgres database. ...
1
vote
1answer
22 views

SQL injection in pandas; binding list to params in SQLAlchemy

I have this SQL query: sql = "select * from table where date in {dl}" where dl is a tuple of dates. I can do the query by doing string.format(dl=...) then using read_sql_query in pandas, but I read ...
0
votes
0answers
14 views

Python dataset database error

I wrote a little script that iterates a feed in a social network and publishes not yet published postings in another social network. I do that in 2 steps: first I read the feed of the first social ...
0
votes
2answers
14 views

How to use NOT IN clause in sqlalchemy ORM query

how do i convert the following mysql query to sqlalchemy? SELECT * FROM `table_a` ta, `table_b` tb where 1 AND ta.id = tb.id AND ta.id not in (select id from `table_c`) so far i have this for ...
0
votes
0answers
6 views

Cannot get Flask-Admin to work with relation + form_columns at the same time

I cannot get Flask-Admin to work with both ForeignKey relation and form_columns (for controlling the order of fields). There is a many-to-one relation between Login and Account, which are defined as ...
0
votes
1answer
12 views

Creating a set-like mapped attribute in SQLAlchemy

I've done some reading and Googling, but am still not sure if there is a native / built-in way to create a mapped attribute in an SQLAlchemy object, that creates a set-like attribute for a similar ...
2
votes
0answers
17 views

How to implement an append-only versioned model in SQLAlchemy

I would like to re-implement some of my existing SQLAlchemy models in an append-only datastore; append-only meaning that object are only updated with INSERT statements, not using UPDATE or DELETE ...
2
votes
1answer
12 views

Sqlalchemy keyed tuple error with select distinct

Keyed tuple objects returned by the same select distinct query, but created differently, are completely different, even though the result is the same. Below is an example demonstrating this error: ...
0
votes
0answers
18 views

How can I fix this IndentationError? [on hold]

I get the following error: IndentationError: unexpected indent error at line 11 when running this code: from sqlalchemy import * db = create_engine('sqlite:///joindemo.db') db.echo = True ...
0
votes
1answer
7 views

How to nest conjunctions or_ and and_ in SQLAlchamey

I'm tyring to recreate this query in SQL Alchamey but I've been unable to nest the filters: Query: SELECT * FROM calendar where (recurrenceRule = '') or (recurrenceRule != '' and start < ...
2
votes
1answer
27 views

what is a good way to pretty print a SQLAlchemy database as models and relations?

This one might be a challenge, but I am trying to find a nice way to get an overarching idea of how my entire database "looks". Here is a small example using Flask-SQLAlchemy, a few models with ...
0
votes
1answer
15 views

filter on multiple columns in subquery [duplicate]

I need to be able to filter on a multiple column row in a subquery In sql this would be something like where (account_details.account_detail_id, tasks.base_action_type_id) IN ( SELECT ...
0
votes
1answer
13 views

How in SqlAlchemy execute “left outer join”

I needed to execute this query:: select field11, field12 from Table_1 t1 left outer join Table_2 t2 ON t2.tbl1_id = t1.tbl1_id where t2.tbl2_id is null I had this classes in python: class ...
0
votes
1answer
17 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 ...
0
votes
1answer
12 views

Why are there different ways to select using SQLAlchemy?

I am confused about the different ways to do select queries. The first way I see is to use direct table object and its select() function. However, if the query requires joins operations it seems you ...
1
vote
1answer
13 views

Python, Flask, SQLAlchemy: cannot import from models

I've got a weird problem. I am building a Flask app with SQLAlchemy. I have a file with models, namely, models.py. And I have a User model there. If I open my "views.py" and insert a string import ...
-1
votes
2answers
28 views

How can I set the user's ip as column default?

When a user is registered, I want to record their ip address. How do I access the current ip and set it as the column default? regi_ip = db.Column(db.String(24), default='???')
0
votes
1answer
17 views

SQLAlchemy: Counting and ordering by multiple relationships to the same table

I have a class in SQLAlchemy that has multiple relationships to the same secondary table. It looks somewhat like this: class Job(Base): __tablename__ = 'jobs' id = Column(Integer, ...
0
votes
1answer
35 views

SqlAlchemy converting UTC DateTime to local time before saving

I have the following situation: - Postgres backend with a field timestamp without time zone Right before saving the datetime value, it looks like : 2014-09-29 06:00:00+00:00 I then load the same ...
0
votes
0answers
12 views

SQLAlchemy: changing child object from a parent in the detached state

I have two classes mapped in SQLAlchemy with a parent-child relationship between them: class UserFile(SQLModel, Base): __tablename__ = "user_file" _id = Column(Integer, ...
0
votes
0answers
8 views

How to increase poolsize in sqlalchmey

Getting TimeoutError in sqlalchmey when using with pyramid TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30 extension = ZopeTransactionExtension() ...
0
votes
1answer
13 views

Correct pattern for inserting row in SQLAlchemy

I have an insert action that is kinda complex, it boils to: input: list of tags, book name INSERT INTO books (book_name) VALUES (book name) for each tag: if tag does not exist: INSERT INTO tags ...
-1
votes
1answer
31 views

Python HATEOAS using a micro framework like eve that runs on top of sqlalchemy [closed]

The eve project in python is by far the easiest way to create RESTful applications with links for me. It's been using mongo in the background and I reckon there are few attempts at making use of ...
0
votes
0answers
26 views

sqlalchemy: compare datetime field with string?

I have a string contains date like '2014-09-28' and want to search through model like following: Log.query.filter(Log.created_at >= from_date) For a record which has datetime.datetime(2014, 9, ...
0
votes
0answers
27 views

pandas 0.14.1 read_sql_query <= not working

Why the code below not returning <= and returning <? from dateutil import parser from sqlalchemy import create_engine import datetime import pandas as pd a=[['Date', 'letters', 'data1', ...
0
votes
1answer
18 views

Strange TypeError when migrating database

After migrating my database a few times, I began to see this error appear on my local server. If I clear the database and re-create it, there is no error, so I don't think there is anything wrong ...
1
vote
0answers
8 views

Bulk update in SQLAlchemy from text query result/ResultProxy or dict

I would like to bulk update an ORM table in SQLAlchemy from a query for which I only have the text and a database connection. I cannot easily (I believe) reflect the source query in the ORM because it ...
0
votes
0answers
9 views

Sqlalchemy same model, diffent tables

I have to write a webpage to display statistics about diffrent games sp there is a database which contaitains all these statistics. I decided to use sqlalchemy to access that database but I got the ...
0
votes
0answers
14 views

Adding objects to multiple databases in Flask-SQLAlchemy Openshift

I am trying to add two separate objects to two databases using SQLAlchemy in a flask application hosted on Openshift. I have two databases joined by a bind using ...
0
votes
0answers
12 views

SQL - SQLAlchemy - How to grab a list of data map from a list

I have a current iteration of list that contains names of items. Each name I query and returns a value that I need. Instead can I grab and return every task_runtime value to the corresponding name in ...
0
votes
1answer
8 views

How to create a migration script with dialect types (HSTORE) in SQLAlchemy-Migrate?

How do you create a migration script that supports dialect data types? Here's an example of a model: db = SQLAlchemy() class Event(db.Model): __tablename__ = 'event' id = ...
1
vote
2answers
22 views

Filter SQLAlchemy one-to-many with “does not contain”

I'm attempting to query and filter on a one-to-many relationship and cannot seem to figure out how to do this. Here are my mappings (trimmed for brevity): class Bug(Base): __tablename__ = 'bug' ...
1
vote
1answer
25 views

Can polymorhpic_on be used over more than one column?

I have a table (and I am not allowed to change it's schema) which contains rows that are represented by three classes. The values in columns a and b determine which class corresponds to a row. if ...
0
votes
1answer
39 views

Self-referential database with extra fields in sqlalchemy

I want to write a self-referential database structure for my messaging system using Flask and SQLAlchemy. Tables are very simple: class User(db.Model): __tablename__ = 'user' id = ...
1
vote
1answer
17 views

SQLAlchemy Inserting into Existing Table, default item value for columns unspecified in Model

Let's say that I have an existing table that I want to map to that contains 10 columns; however, I only care about writing to 3 of these columns, via a specified Model. If I insert a record according ...
0
votes
1answer
17 views

Flask-SQLAlchemy join

Hello I have a problem with join at flask-sqlalchemy. I am a beginner at database and flask. These are my classes: class Shopping(db.Model): __tablename__ = 'shoppings' id = ...
0
votes
1answer
11 views

Cannot access column in PostgreSQL table from Python model

I have defined a python class "Students", like this: class Students(DeclarativeBase): __tablename__ = 'students' id_ = Column('id', Integer, primary_key=True) name = Column('nombre', ...
0
votes
2answers
28 views

SQLAlchemy, select such A that has at least one B with raised flag

I have two tables: class A(Base): id = Column(Integer, primary_key=True) class B(Base): id = Column(Integer, primary_key=True) a_id = Column(Integer, ForeignKey('a.id')) a = ...
0
votes
0answers
31 views

Why might a session not be current?

I have a unit test defined like so. The setUp works correctly. Config is a dictionary with the location of the mysql executable and the name of the database. import unittest #mercury from ...
1
vote
0answers
25 views

How to write nested conjunctions (OR and AND clauses) in SQLAlchemy?

Does anybody know how to produce nested conjunctions in SQLAlchemy? I have some Python code similar to this: import sqlalchemy as sa a = sa.and_(mytable.col1 > 1, mytable.col2 < 3) b = ...
0
votes
0answers
17 views

SQLAlchemy Join expressions without nesting

How does one join two Select objects without generating unnecessary query nesting? Example Set up two select statements In [1]: import sqlalchemy as sa In [2]: metadata = sa.MetaData() In [3]: ...
0
votes
1answer
9 views

Mapping multi-level class inheritance hierarchies in SqlAlchemy

Background I have an existing database with 3 levels of dependent tables. Here I give an example of a 3-level, joined table, inheritance mapping problem I cannot solve. Unfortunately I cannot change ...
0
votes
2answers
24 views

SQLAlchemy proper Model definition and Selecting / Inserting [closed]

I'm having trouble with SQL Alchemy with both setting up the models and selecting / inserting If I setup the model as follows and insert in item into a table, it works: #!/usr/bin/python import ...
0
votes
1answer
14 views

Does a .py get executed when being imported [python3]

I need to execute a file, so I was wondering if it works like this? The file that needs to be executed would create a database.
0
votes
1answer
21 views

What the heck do I get when I subclass `declarative_base` using SqlAlchemy?

I have a simple SqlAlchemy application: import sqlalchemy as sa import sqlalchemy.ext.declarative as dec import sqlalchemy.engine.url as saurl import sqlalchemy.orm as saorm import sqlalchemy.schema ...
0
votes
1answer
29 views

SQLAlchemy error on upsert

I am getting the following error on a SQLAlchemy add: sqlalchemy.exc.IntegrityError: (IntegrityError) duplicate key value violates unique constraint "posts_pkey" DETAIL: Key (id)=(TEST1234) already ...
0
votes
0answers
17 views

Is it possible to declare relationship after class is created by automap in SqlAlchemy

I'm new to sqlalchemy. I have followed the tutorial to create the automap of a existing db with relationship from a mysql db from sqlalchemy import create_engine, MetaData, Column, Table, ForeignKey ...