[sqlalchemy] too many SQL variables in "in_"

2014-09-04 Thread mando
Hi to all, I wrote a method like this to reuse the code for many tables at the same time[0] But, with more than 1000 records sqlite doesn't accepts the amount of id inside .in_(id_list) How can I filter, split or can manage it? Thanks a lot and best regards, Luca [0] def query_sort(self,id_

Re: [sqlalchemy] Issue with return results

2014-09-04 Thread Greg Silverman
I think I am going to dump SQL Server and just go with Postgres. Much easier, and less of a headache. Fortunately, we are not yet in production. Thanks! Greg-- On Thu, Sep 4, 2014 at 8:31 PM, Horcle wrote: > Thanks. I forgot to mention that I had tried adding the encoding scheme to > freetds.

Re: [sqlalchemy] More than one level of abstract base classes doesn't work

2014-09-04 Thread Michael Bayer
well that's just a simple bug. this fixes: diff --git a/lib/sqlalchemy/ext/declarative/api.py b/lib/sqlalchemy/ext/declarative/api.py index daf8bff..fe64ee7 100644 --- a/lib/sqlalchemy/ext/declarative/api.py +++ b/lib/sqlalchemy/ext/declarative/api.py @@ -396,7 +396,7 @@ class AbstractConcreteBa

[sqlalchemy] More than one level of abstract base classes doesn't work

2014-09-04 Thread Alex Grönholm
The following code fails with AttributeError: 'NoneType' object has no attribute 'concrete': from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import AbstractConcreteBase, declarative_base Base = declarative_base() class Document(Base, AbstractConcreteBase)

Re: [sqlalchemy] Issue with return results

2014-09-04 Thread Horcle
Thanks. I forgot to mention that I had tried adding the encoding scheme to freetds.conf. I also tried other encoding schemes, all to no avail. I may try pymssql tomorrow to see what that does. I would have tried mxodbc, but I am not about to pay $379 for a driver. I may also see if I can get the

Re: [sqlalchemy] Session.close() appears to infrequently not expunge all objects

2014-09-04 Thread Michael Bayer
On Sep 4, 2014, at 8:17 PM, Lonnie Hutchinson wrote: > The session executes in one of many web-server threads, but there is no > multi-threading with respect to the session or the objects. The session that > was closed is within an initializer and upon return a method on the object is > execu

Re: [sqlalchemy] Multiple delete attempts of same rows with a star schema configuration

2014-09-04 Thread Ken Lareau
On Thu, Sep 4, 2014 at 4:54 PM, Michael Bayer wrote: > > On Sep 4, 2014, at 7:50 PM, Ken Lareau wrote: > > > Is there a way to essentially allow something like 'for app in > project.applications:' without having > to make an explicit query to the DB first, but avoiding the awkwardness of > the c

Re: [sqlalchemy] Session.close() appears to infrequently not expunge all objects

2014-09-04 Thread Lonnie Hutchinson
The session executes in one of many web-server threads, but there is no multi-threading with respect to the session or the objects. The session that was closed is within an initializer and upon return a method on the object is executed that creates a new session and tries to attach objects retrieve

Re: [sqlalchemy] Multiple delete attempts of same rows with a star schema configuration

2014-09-04 Thread Michael Bayer
On Sep 4, 2014, at 7:50 PM, Ken Lareau wrote: > > Is there a way to essentially allow something like 'for app in > project.applications:' without having > to make an explicit query to the DB first, but avoiding the awkwardness of > the current setup? just use the viewonly=True and we can al

Re: [sqlalchemy] Multiple delete attempts of same rows with a star schema configuration

2014-09-04 Thread Ken Lareau
On Thu, Sep 4, 2014 at 4:35 PM, Michael Bayer wrote: > > On Sep 4, 2014, at 6:58 PM, Ken Lareau wrote: > > On Thu, Sep 4, 2014 at 3:30 PM, Michael Bayer > wrote: > >> >> On Sep 4, 2014, at 5:37 PM, Ken Lareau wrote: >> >> So I have a few tables as follows (abbreviated for unnecessary columns):

Re: [sqlalchemy] Multiple delete attempts of same rows with a star schema configuration

2014-09-04 Thread Michael Bayer
On Sep 4, 2014, at 6:58 PM, Ken Lareau wrote: > On Thu, Sep 4, 2014 at 3:30 PM, Michael Bayer > wrote: > > On Sep 4, 2014, at 5:37 PM, Ken Lareau wrote: > >> So I have a few tables as follows (abbreviated for unnecessary columns): >> >> class Project(Base): >> __tablename__ = 'projects

Re: [sqlalchemy] Multiple delete attempts of same rows with a star schema configuration

2014-09-04 Thread Ken Lareau
On Thu, Sep 4, 2014 at 3:30 PM, Michael Bayer wrote: > > On Sep 4, 2014, at 5:37 PM, Ken Lareau wrote: > > So I have a few tables as follows (abbreviated for unnecessary columns): > > class Project(Base): > __tablename__ = 'projects' > > id = Column(u'project_id', INTEGER(), primary_key=

Re: [sqlalchemy] Multiple delete attempts of same rows with a star schema configuration

2014-09-04 Thread Michael Bayer
On Sep 4, 2014, at 5:37 PM, Ken Lareau wrote: > So I have a few tables as follows (abbreviated for unnecessary columns): > > class Project(Base): > __tablename__ = 'projects' > > id = Column(u'project_id', INTEGER(), primary_key=True) > > applications = relationship( > 'Ap

Re: [sqlalchemy] Issue with return results

2014-09-04 Thread Michael Bayer
SQL Server and unix, many things can change: - UnixODBC version - FreeTDS version (0.82 and 0.91 have *extremely* different behaviors) - FreeTDS configuration The first place I'd look in this case would be your freetds.conf, you probably need to configure the character set correctly in there.

Re: [sqlalchemy] Session.close() appears to infrequently not expunge all objects

2014-09-04 Thread Michael Bayer
On Sep 4, 2014, at 5:00 PM, Lonnie Hutchinson wrote: > > > I am using sqlalchemy 0.8.5 with mysql 5.5 and think an intermittent failure > I am seeing may be due to an issue in sqlalchemy. Very infrequently I receive > an error from Session.add() stating the instance "is already attached to

[sqlalchemy] Multiple delete attempts of same rows with a star schema configuration

2014-09-04 Thread Ken Lareau
So I have a few tables as follows (abbreviated for unnecessary columns): class Project(Base): __tablename__ = 'projects' id = Column(u'project_id', INTEGER(), primary_key=True) applications = relationship( 'AppDefinition', secondary=lambda: Base.metadata.tables['proje

[sqlalchemy] Issue with return results

2014-09-04 Thread Horcle
I had to reinstall my python dev environment from scratch due to a hd failure, and in the process something seems to have changed. When querying against MS SQL using the script (test_conenction.py): import pyodbc import sqlalchemy from sqlalchemy.engine import reflection from sqlalchemy.engine.r

[sqlalchemy] Session.close() appears to infrequently not expunge all objects

2014-09-04 Thread Lonnie Hutchinson
I am using sqlalchemy 0.8.5 with mysql 5.5 and think an intermittent failure I am seeing may be due to an issue in sqlalchemy. Very infrequently I receive an error from Session.add() stating the instance "is already attached to session 'XXX' (this is 'YYY')" (see below for stack trace). I un

Re: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Ofir Herzas
Thanks Jonathan, I actually have more properties and relationships which were removed for the sake of the example. You are right though, the performance gain was not as I hoped it would be. I'll have to think of other methods (caching maybe)... On Sep 4, 2014 11:50 PM, "Jonathan Vanasco" wrote:

Re: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Jonathan Vanasco
On Thursday, September 4, 2014 2:19:34 PM UTC-4, Ofir Herzas wrote: > > Nevertheless, is there a way to achieve what I want? (which is to > selectively load several columns and this 'jobs' property from Employee) > The ways I usually do that are: 1. Select the other object. Query for Employe

RE: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Ofir Herzas
Thanks Simon, it worked! I did the whole thing just because I had an sql select query talking 1.5 seconds to complete (several joins and many properties, just 1000 records), and this change reduced it to 1.1 seconds (I guess I'll have to find a better way to improve performance) -Original Mes

Re: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Simon King
You need to join along the actual relationships between your classes. You've got this: Employee._jobs -> EmployeeJob.? -> Job (I assume EmployeeJob has a "job" relationship to Job.) I think you probably want something like this: (session.query(Employee) .options(load_only('id', 'f

RE: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Ofir Herzas
Nevertheless, is there a way to achieve what I want? (which is to selectively load several columns and this 'jobs' property from Employee) Thanks, Ofir From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Michael Bayer Sent: Thursday, September 04, 2014 8:

Re: [sqlalchemy] Wrapping polymorphic model for Pyramid traversal

2014-09-04 Thread Milo Toor
OK, thanks for the reply Mike! On Thursday, September 4, 2014 8:45:24 AM UTC-7, Michael Bayer wrote: > > this is probably more of a Pyramid question. > > I’m pretty allergic to traversal myself :) > > > On Sep 3, 2014, at 2:58 PM, Milo Toor > > wrote: > > Hi. > > I am trying to wrap a polymorphic

Re: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Michael Bayer
On Sep 4, 2014, at 1:32 PM, Ofir Herzas wrote: > Thanks Michael, > I'm using 0.9.7 and while your example did work, the following did not: Ok that's not a relationship(). joinedload() only works with relationships. > > from sqlalchemy import * > from sqlalchemy.orm import * > from sqlalc

RE: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Ofir Herzas
Thanks Michael, I'm using 0.9.7 and while your example did work, the following did not: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Employee(Base): __tablename__ = 'employee'

Re: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Michael Bayer
On Sep 4, 2014, at 12:28 PM, Ofir Herzas wrote: > Thanks Simon, > I've tried the following: > > session.query(Employee).options(sa.orm.joinedload(Employee.jobs).load_only('id', > 'first_name')).all() > > which according to the documentation > (http://docs.sqlalchemy.org/en/rel_0_9/orm/mapper

Re: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Jonathan Vanasco
load_only indicates the columns in Employee.jobs that you want to load. 'first_name' is located on Employee, not EmployeeJob -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an

Re: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Ofir Herzas
Thanks Simon, I've tried the following: session.query(Employee).options(sa.orm.joinedload(Employee.jobs).load_only( 'id', 'first_name')).all() which according to the documentation ( http://docs.sqlalchemy.org/en/rel_0_9/orm/mapper_config.html#deferred-loading-with-multiple-entities) should work

[sqlalchemy] Re: adding columns dynamically to an ORM class ?

2014-09-04 Thread Jonathan Vanasco
nevermind, i overthought this. apparently this is all i needed: model.TableClass.temp_column = sqlalchemy.Column(sqlalchemy.Integer) -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails fr

[sqlalchemy] adding columns dynamically to an ORM class ?

2014-09-04 Thread Jonathan Vanasco
is it possible to add a column to an ORM class after the engine and mapper have initialized? I have a maintenance/migration script that needs a new column on the table for the duration of the script. For a variety of reasons, I need to avoid altering the actual model. I found `append_column`

Re: [sqlalchemy] Query filter NameError issue

2014-09-04 Thread Michael Bayer
Hi Gilles - if you've imported "models", you need to refer to Series as "models.Series", unless you imported Series individually which seems to not be the case. The second part of things, if you call query.filter(), you get a new Query object back, just like with most Query methods, until you d

Re: [sqlalchemy] Wrapping polymorphic model for Pyramid traversal

2014-09-04 Thread Michael Bayer
this is probably more of a Pyramid question. I'm pretty allergic to traversal myself :) On Sep 3, 2014, at 2:58 PM, Milo Toor wrote: > Hi. > > I am trying to wrap a polymorphic model so that it can act as a traversal > node in a Pyramid application: > > from sqlalchemy import Column, Intege

Re: [sqlalchemy] Selecting columns from multiple table join in SQLAlchemy Core

2014-09-04 Thread Michael Bayer
I think the join.select(columns, whereclasue) part here is wrong, the select() method unfortunately does not have that calling signature (I wish it did, but there's a lot of legacy there). You can get the columns you want more explicitly, select([c1, c2, c3, ..]).select_from(my_join). The exc

[sqlalchemy] Re: Selecting columns from multiple table join in SQLAlchemy Core

2014-09-04 Thread Jonathan Vanasco
the first thing I noticed, is that you're referencing the "idea" of the tables in two separate ways : `self.execs` and `execs` are they the same python object? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and st

Re: [sqlalchemy] selecting from a relationship

2014-09-04 Thread Simon King
On Thu, Sep 4, 2014 at 3:28 PM, Ofir Herzas wrote: > Hi, > I have a model similar to the following: > > class Employee(Base): > __tablename__ = "t_employee" > > id = sa.Column(Identifier, sa.Sequence('%s_id_seq' % __tablename__), > primary_key=True, nullable=False) > first_name = sa.Co

[sqlalchemy] selecting from a relationship

2014-09-04 Thread Ofir Herzas
Hi, I have a model similar to the following: class Employee(Base): __tablename__ = "t_employee" id = sa.Column(Identifier, sa.Sequence('%s_id_seq' % __tablename__), primary_key=True, nullable=False) first_name = sa.Column(sa.String(30)) last_name = sa.Column(sa.String(30))