Tagged Questions
0
votes
0answers
21 views
Order by issue when outer joining two tables in sqlalchemy
I am a noob trying to use flask with sqlalchemy and am having an issue sorting result from a base query.
I have a parent table and two joined many-to-many association tables:
class ...
0
votes
0answers
14 views
Alembic - sqlalchemy initial migration
I am having a problem creating an initial migration which would automatically have tables that I've defined in my models.py by using shared Base (declarative_base).
When I enter a command:
alembic ...
0
votes
1answer
11 views
SQLAlchemy : Column name on union_all
Here is the mssql code snippet
(Select column_name_1 from table_name_1 with(nolock) Where column_name_2='Y'
UNION ALL
Select column_name_1 from table_name_2 with(nolock) Where column_name_2='Y'
...
0
votes
1answer
8 views
sqlalchemy non-keyword arg after keyword arg
When I try to define a Foreign Key constraint, I am getting the following error(syntax error)
class StopName(Base):
'''
Class Model for StopNames
'''
__tablename__ = 'STOP_NAME'
uid = ...
-1
votes
1answer
41 views
Difference in SQL [on hold]
I am planning on learning SQL.
I am looking at SQLAlchemy, since I am rather familiar with Python.
I am wanting to know, is SQL the same even if the sql is in MySQL or MSSQL or any other. Or is it ...
0
votes
1answer
10 views
Sqlalchemy (and alembic) Concrete table inheritance without polymorphic union
I'm new to SQLAlchmey, and I'm trying to achieve the following objects/db tables structure (by using alembic as well):
class BaseConfig(Base):
pk = Column(Integer, primary_key=True)
name = ...
0
votes
0answers
22 views
Flask-Admin and custom field in model
I have tables similar to the following:
class User(Base):
id = Column(Integer, primary_key=True)
name = Column(String(255, unique=True)
class Document(Base):
id = Column(Integer, ...
0
votes
0answers
10 views
psycopg2._psycopg.connection object is not callable
I'm trying to create a connection pool and am following the example on the sqlalchemy page and I'm wondering why I'm seeing this error. I am running the following code:
import sqlalchemy.pool as ...
1
vote
0answers
34 views
How can I truncate a table using pandas?
I have a function that is executed few times, each time it appends elements to a table on SQL Server using this code:
import pandas as pd
import pandas.io.sql as pdsql
import pyodbc
params = ...
1
vote
0answers
20 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
23 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
13 views
Is the use of Parent and Child class names in SQLAlchemy documentation meaningful?
Immediately upon reading about relationship configuration in the SQLAlchemy docs, it's easy to wonder why class names "Parent" and "Child" were chosen for the examples. This usually implies ...
0
votes
0answers
42 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
26 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
16 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
16 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
13 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
41 views
+50
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
19 views
How can I fix this IndentationError? [closed]
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
29 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
16 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
15 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
20 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
18 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
36 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
34 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
27 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
29 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
9 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
10 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
18 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
12 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 = ...