sqlalchemy

Managing many many-to-many relations with sqlalchemy when deletes come up

Lets say I have an email table which stands in relation to contact and organization tables. Contact and Organization objects can have several Email children, and, the same Email is not necessarily uniquely associated with any one parent. Relationships are accomplished via secondary tables. (I.e. contact_email, and org_email, which con...

SQLAlchemy and max_allowed_packet problem

Due to the nature of my application, I need to support fast inserts of large volumes of data into the database. Using executemany() increases performance, but there's a caveat. For example, MySQL has a configuration parameter called max_allowed_packet, and if the total size of my insert queries exceeds its value, MySQL throws an error. ...

Sum fields in sqlAlchemy

I recently upgraded to the most recent version of sqlalchemy and some of my code no longer works. I'm having difficulty finding how to fix it and could use a hand. Previously the query appeared as so. self.db.query(Drive).filter(Drive.package_id==package.package_id)\ .filter(Drive.wipe_end!=None).sum(Drive.wipe_end - Drive.wipe_sta...

SQLAlchemy only loads collection, not backref when eagerloading.

For example (eagerload/joinedload do the same thing): session = Session() parents = session.query(Parent).options(joinedload(Parent.children)).all() session.close() print parents[0].children # This works print parents[0].children[0].parent # This gives a lazy loading error Adding the following loop before closing the session wo...

SQLAlchemy truncating Column=(Integer)

Hi guys, weird issue here: I have a reflected SQL alchemy class that looks like this: class Install(Base): __tablename__ = 'install' id = Column(Integer, primary_key=True) ip_address = Column(Integer) I convert the string representation ("1.2.3.4") to int using: struct.unpack('!L', socket.inet_aton(ip_address))[0] This...

Foreign key relationships missing when reflecting db in SqlAlchemy

I am attempting to use SqlAlchemy (0.5.8) to interface with a legacy database declaratively and using reflection. My test code looks like this: from sqlalchemy import * from sqlalchemy.orm import create_session from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() engine = create_engine('oracle://schemaname:...

How to generate this query in sqlalchemy ?

I want to generate this query in sqlalchemy. The table 'demande' exists in the database. There is a subquery that generates the timesteps with the generate_series function. SELECT timesteps.timestep AS timestep, d.count AS count FROM (SELECT DATE_TRUNC('hour',date_demande) AS timestep, COUNT(id) AS count FRO...

SQL Alchemy - How to Delete from a model instance?

Say I get a model instance like this: instance = session.query(MyModel).filter_by(id=1).first() How can I delete that row? Is there a special method to call? ...

Elixir/SQLAlchemy equivalent to SQL "LIKE" statement?

I'm using the MySQLicious type schema described here for a simple tagging system. I've read some alternative implementations of tagging schema in 4 different SO threads, and this suits my needs best. A collection of entries have the tags "apple banana orange" and "strawberry banana lemon", and I'm trying to find the Elixir/SQLAlchemy eq...

sqlalchemy filter multiple columns

How do I combine two columns and apply filter? For example, I want to search in both the "firstname" and "lastname" columns at the same time. Here is how I have been doing it if searching only one column: query = meta.Session.query(User).filter(User.firstname.like(searchVar)) ...

Creating Stored Procedures with SQLAlchemy

Hi, I am writing a python script to create the postgres database using SQLAlchemy. I also want to create Stored Procedures by same way. I checked the SQL Alchemy Documentations but was not able to find whether I can create stored procedure using it or not. Is it Possible to do so? any Tutorials/Examples would help. i found some examples...

sqlalchemy in a single python script file

I've read about using sqlalchemywithin the pylons framework. How will things work if I need it for a simple script file? I have like importer.py that is spidering a site and I want to save to mysql. If things are in a single file, can I still using sqlalchemy? How do I setup my model/mappings then? ...

UUID returning as bytes_le from MS SQL

I'm querying a table from my Django app, but whenever I do a query on one specific table, I am getting the UUID column returned as a bytes_le style UUID instead of a workable string representation. Now, I know I convert it using uuid.UUID(bytes_le=value), but I'm using this query to populate a WTForms QuerySelectField, so I don't really...

Pylons 1.0 and SQLAlchemy 0.6 - How do I Model?

I've been reading http://pylonsbook.com/en/1.1/starting-the-simplesite-tutorial.html and following along with their SimpleSite tutorial but am having some issues with creating the Model. The Model imports they use on the tutorial are: """The application's model objects""" import sqlalchemy as sa from sqlalchemy import orm from simples...

Python - SqlAlchemy. How to relate tables from different modules or files?

I have this class in one file and item class in another file in the same module. If they are in different modules or files when I define a new Channel, I got an error because Item is not in the same file. How can I solve this problem? If both classes are in the same file, I don't get any error. ChannelTest.py from ItemTest import Item ...

Sql Alchemy connecion time Out

I am using sqlalchemy with Mysql, and executing query with sql expression . when executing a number of query then it time out. I found an answer but it is not clear to me -- Answer link . plz any one can help me? TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30 ...

How to specify Check Constraint on Varchar Datatype column in SQLALchemy?

Hi, I am trying to specify this check constraint on a column via SQLAlchemy. delete_flag char(1) not null CHECK(delete_flag in('Y','N')), I am not able to figure out the syntax to achieve this. Any link, tutorial, advise will be of great help. Thanks Tara Singh ...

Way to query database with SQLAlchemy where a date is a particular day of the week?

I have a table (called 'entry') which has a datetime column (called 'access_date'), and I want to do an SQLAlchemy query that only produces results where entry.access_date is a Monday (or any other day of the week specified by a number [0..6]). Is this possible? I am using sqlite & SQLalchemy 0.5.8 if that makes any difference. ...

sqlachemy, says decimal is not defined?

Trying to make a column of type decimal: Column('cost', DECIMAL) Erorr, name 'DECIMAL' is not defined. SqlAlch seems to support decimal, am I missing an import? BTW, how do I also create a longtext column? I'm using mysql. ...

sqlachemy created mysql table, but I modified table now says 'unknown column url'

I added a url column in my table, and now sqlalchemy is saying 'unknown column url'. Why isn't it updating the table? There must be a setting when I create the session? I am doing: Session = sessionmaker(bind=engine) Is there something I am missing? I want it to update any table that doesn't have a property that I added to my Tabl...