sqlalchemy

Why would I get an intermittent UnboundExecutionError from SQLAlchemy on second WSGI request?

I am building a small WSGI application and I am having an intermittent problem with SQLAlchemy throwing an UnboundExceptionError. When it happens, it seems to happen exclusively on the second request the browser makes. Refreshing the page (and all following page view attempts) run fine. It seems to only happen on the second request. I ...

sqlalchemy quering a view

Hello there, i want to know if sqlalchemy has some problems querying a view? Because if i query the view with normal sql on the server like: select * from ViewMyTable where index1 = '608_56_56'; i get a hole butch of entries. But with SQLAlchemy i get only the first one. But in the count is the correct number. I have no idea why...

SQLAlchemy and Can't Adapt.

Hi. I have the following exception when using sqlalchemy on postgres: raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) ProgrammingError: (ProgrammingError) can't adapt 'UPDATE doc_data SET content=%(content)s WHERE doc_data.serial_id = %(doc_data_serial_id)s' {'content': 'Progr...

SQLAlchemy Column to Row Transformation and vice versa -- is it possible?

I'm looking for a SQLAlchemy only solution for converting a dict received from a form submission into a series of rows in the database, one for each field submitted. This is to handle preferences and settings that vary widely across applications. But, it's very likely applicable to creating pivot table like functionality. I've seen th...

SqlAlchemy add new Field to class and create corresponding column in table

I want to add a field to an existing mapped class, how would I update the sql table automatically. Does sqlalchemy provide a method to update the database with a new column, if a field is added to the class. ...

Merging duplicates in a list? - Question is more complex than it seems

So I have a huge list of entries in a DB (MySql) I'm using Python and Django in the creation of my web application. This is the base Django model I'm using: class DJ(models.Model): alias = models.CharField(max_length=255) #other fields... In my DB I have now duplicates eg. Above & Beyond, Above and Beyond, Above Beyond, ...

Group by hour in SQLAlchemy?

How do I group query results by the hour part of a datetime column in SQLAlchemy? ...

how to save data in a many to many relationship using turbogears and sqlalchemy

hi i have a many to many relationship between a user and a group.and i will like to add a user with many groups in my database.how do i do that if my database is as follows user_group_table = Table('tg_user_group', metadata, Column('user_id', Integer, ForeignKey('tg_user.user_id', onupdate="CASCADE", ondelete="CASCADE")), ...

How to return the count of related entities in sqlalchemy query

I'm new to sqlalchemy, and while the documentation seems fairly thorough, I couldn't find a way to do quite what I want. Say I have two tables: forum and post. Each forum has a parent forum, and any number of posts. What I want is: A list of top-level forums Eagerly loaded child forums accessible through the top-level forums A count o...

Using Django's Model API without having to *include* the full Django stack

Currently an application of mine is using SQLAlchemy, but I have been considering the possibility of using Django model API. Django 1.1.1 is about 3.6 megabytes in size, whereas SQLAlchemy is about 400 kilobytes (as reported by PyPM - which is essentially the size of the files installed by python setup.py install). I would like to use...

What's the difference between filter and filter_by in SQLAlchemy?

Hello everyone! Could anyone explain the difference between filter and filter_by functions in SQLAlchemy? I am confused and can't really see the difference. Which one should I be using? Thanks, Boda Cydo ...

SQLAlchemy printing raw SQL from create()

Hi all I am giving Pylons a try with SQLAlchemy, and I love it, there is just one thing, is it possible to print out the raw SQL CREATE TABLE data generated from Table().create() before it's executed? ...

Is it possible to narrow down the generated query in SQLAlchemy if it was created via query_property?

I have another quick question about SQLAlchemy. If I have added a query_property [1] field in my SQLAlchemy Table class, is it possible to narrow down the SELECTed fields? Here is what I mean. Suppose my class Comments has this: class Comments: query = Session.query_property() ... Then if I do the following: >>> print Ses...

How should I port a Plone product from collective.lead to z3c.saconfig?

I have a Plone product that uses collective.lead to configure SQLAlchemy, including an in-Plone database configuration interface as documented in Professional Plone Development. How should I port this to z3c.saconfig? Will I be able to keep the in-ZODB configuration or will it need to go into site.zcml? ...

Error handling in SQLAlchemy

Hello everyone, How do you handle errors in SQLAlchemy? I am relatively new to SQLAlchemy and do not know yet. Before I used SQLAlchemy, I would do things like status = db.query("INSERT INTO users ...") if (!status): raise Error, db.error But now I am coding in SQLAlchemy and I do things like user = User('Boda Cydo') session.ad...

Is this a memory leak ( a program in python with sqlalchemy/sqlite)

I have the following code runs over a large set of data (2M). It eats up all my 4G mem before finishing. for sample in session.query(CodeSample).yield_per(100): for proj in projects: if sample.filename.startswith(proj.abs_source): sample.filename = "some other path" ...

possible in sqlalchemy to join table based on a column value?

I am trying to create a table to hold user actions on my web app. Take a simple case where a user adds a new story, and comments on it. This will add two entries to the user_action table. In the user_action table I would like to store the module name associated with each action and the items id. In this cause I would store the modules as...

SQLAlchemy sqlalchemy.sql.expression.select vs. sqlalchemy.sql.expression.Select

So I'm brand new to SQLAlchemy, and I'm trying to use the SQL Expression API to create a SELECT statement that specifies the exact columns to return. I found both a class and a function defined in the sqlalchmey.sql.expressions module and I'm not too sure which to use... Why do they have both a class and a function? When would you use on...

How to do a JOIN in SQLAlchemy on 3 tables, where one of them is mapping between other two?

Suppose I have the following tables: Articles with fields article_id, title Tags with fields tag_id, name ArticleTags with fields article_id, tag_id And I wish to find all articles that have a given tag. How do I create this complicated join in SQLAlchemy? In SQL it would look like: SELECT a.article_id, a.title FROM Articles AS a J...

Selecting distinct column values in SQLAlchemy/Elixir

In a little script I'm writing using SQLAlchemy and Elixir, I need to get all the distinct values for a particular column. In ordinary SQL it'd be a simple matter of SELECT DISTINCT `column` FROM `table`; and I know I could just run that query "manually," but I'd rather stick to the SQLAlchemy declarative syntax (and/or Elixir) if I c...