[sqlalchemy] Re: Somewhat complex union_all() question

2009-08-26 Thread Mike Conley
or should be a little better q=q1.union_all(q2,q3) -- Mike Conley On Thu, Aug 27, 2009 at 12:14 AM, Mike Conley wrote: > Did you try something like this? > > q1=session.query(P1.userid, P1.extra, P1.title, P1.body) > q2=session.query(P2.userid, "'X'", P2.ti

[sqlalchemy] Re: Somewhat complex union_all() question

2009-08-26 Thread Mike Conley
Did you try something like this? q1=session.query(P1.userid, P1.extra, P1.title, P1.body) q2=session.query(P2.userid, "'X'", P2.title, P2.body) q3=session.query(P3.userid, "'X'", P3.title, P3.body) q=q1.union_all(q2).union_all(q3) -- Mike Conley

[sqlalchemy] Re: Declarative way of delete-orphan

2009-08-26 Thread Mike Conley
Add cascade='delete-orphan' to the relation definition for children. cascade='all,delete-orphan' is also a fairly common option. See the documentation for other options in cascade. http://www.sqlalchemy.org/docs/05/reference/orm/mapping.html#sqlalchemy.orm.relation -- M

[sqlalchemy] Re: multiple insert with default values

2009-08-26 Thread Mike Conley
x...94f0 COMMIT Implied rule is: when inserting many records, provide same value list for each row. -- Mike Conley On Wed, Aug 26, 2009 at 5:36 AM, menuge wrote: > > Hi all, > > I d like to insert a list of dictionary in a simple MySQL table but, I > have a problem,

[sqlalchemy] Re: Database with "audit trail" table

2009-08-21 Thread Mike Conley
You might want to start here http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegrou

[sqlalchemy] Re: new questions

2009-08-21 Thread Mike Conley
> > but I thought somehow that meta.reflect() would pick up on the fk > constraints ... > Class MetaData is part of the core api that ORM builds on top of, and meta.reflect() does pick up the fk constraints from the database. Think of it this way, MetaData, whether reflected or declared in its en

[sqlalchemy] Re: Deleting multiple objects

2009-08-19 Thread Mike Conley
u read the documentation for Query.delete() to understand the impact of the 'synchronize_session' keyword -- Mike Conley On Wed, Aug 19, 2009 at 5:54 PM, wrote: > > Hello, > > I have several objects from a relation that I'd like to delete. To me, > this would be a natural

[sqlalchemy] Re: Mapping to multiple tables

2009-08-15 Thread Mike Conley
skills related to a profile, and each skill related to a user. -- Mike Conley On Sat, Aug 15, 2009 at 5:19 PM, Sid wrote: > > Hi, > > I'm new to SQLAlchemy and ORMs in general so I have a couple of > questions. > > Basically I have a class called Profile that conta

[sqlalchemy] Re: Proper way to use case() in a filter()?

2009-08-11 Thread Mike Conley
kt,ut.c.uid==ukt.c.uid)).\ filter(case([(ut.c.uid=='mike','M'), (ut.c.uid=='sue','F')], else_='X') == 'M') -- Mike Conley --~--~-~--~~~---~--~~ You received this message

[sqlalchemy] Updating a self referential relation

2009-08-07 Thread Mike Conley
I can do this by adding a method to People def marries(self, other): self.spouse = other other.spouse = self and then saying sue.marries(sam) to record the two way relationship Question: Adding the method is very simple and clear. For my education, is there

[sqlalchemy] Re: missing parenthesis on generated query?

2009-08-05 Thread Mike Conley
(a AND b) OR c are equivalent. When a or b is a complex condition that also has OR then parenthesis are probably needed. In this case, it appears that the condition is an OR of two conditions that consist entirely of AND conditions. If that is the case then parenthesis are not required.

[sqlalchemy] Re: Accessing attributes hidden by a join

2009-08-04 Thread Mike Conley
eed to use the join(), construct a selectable that explicitly names the columns you want to select. -- Mike Conley On Tue, Aug 4, 2009 at 8:44 AM, Nathan Harmston < iwanttobeabad...@googlemail.com> wrote: > > Hi everyone, I am trying to get access to attributes which are hidden b

[sqlalchemy] Re: declarative_base vs mapper

2009-07-29 Thread Mike Conley
> What are the advantages of using declarative way of setting table > definitions? vs > addressbook_table = sqlalchemy.Table("Addressbook", metadata, >sqlalchemy.Column('Address_Sid', sqlalchemy.Integer, primary_key=True), >sqlalchemy.Column('FirstName', sqlalchemy.Unicode(40),nullable=Fals

[sqlalchemy] Re: declarative_base vs mapper

2009-07-29 Thread Mike Conley
2 lines before metadata.create_all(), then you don't need to separately create the index. -- Mike Conley On Wed, Jul 29, 2009 at 5:34 PM, Lukasz Szybalski wrote: > > Hello, > How can I do > Index('myindex', xyz.c.type, xyz.c.name, unique=True) > > in

[sqlalchemy] Cloning an instance of a mapped class

2009-07-29 Thread Mike Conley
different value session.add(newobj) session.commit() This seems to work for the simple cases I ran so far, just wondering if there are any hidden problems or simplifications. -- Mike Conley --~--~-~--~~~---~--~~ You received this message because you are subscribed to

[sqlalchemy] Re: Single row of a One to Many query

2009-07-24 Thread Mike Conley
ord==O.onum))) If needed this can probably be optimized for efficiency -- Mike Conley On Fri, Jul 24, 2009 at 4:32 AM, Noufal wrote: > > Hello everyone, > I've been using sqlalchemy with elixir for a legacy project for a > while now and recently needed to write some more

[sqlalchemy] lazy=False generated bad SQL

2009-07-23 Thread Mike Conley
= query.options(contains_eager(Slide.bullets)) The problem with this is that I lost much of the relational simplicity. I had to add join and ordering clauses to my query that were already specified in the relation definition. Am I missing something? Maybe another way of specifying order_by in th

[sqlalchemy] Re: Specifying Alternate Join Conditions to relation()

2009-07-15 Thread Mike Conley
like this. boston_addresses = relation('Address', primaryjoin = "and_(User.user_id==Address.user_id,Address.city=='Boston')" ) -- Mike Conley --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Gro

[sqlalchemy] Re: Specifying Alternate Join Conditions to relation()

2009-07-15 Thread Mike Conley
uct also? http://www.sqlalchemy.org/docs/05/mappers.html#specifying-alternate-join-conditions-to-relation I can reproduce GHZ's error with declarative, but also can run the documentation example using mappers. Can we express the alternate joins with declarative? -- Mike Conley On Wed, Jul 15, 2009

[sqlalchemy] Re: Unique parent class and various subclasses

2009-07-07 Thread Mike Conley
straint is right, then it looks like you are getting correct behavior. Posting your table definitions also would help. -- Mike Conley On Tue, Jul 7, 2009 at 12:12 PM, Nathan Harmston < iwanttobeabad...@googlemail.com> wrote: > > Hi, > Currently I have a mapper like this: >

[sqlalchemy] Re: relation error?

2009-06-17 Thread Mike Conley
uot; would work, but this would not: "u.room.name = 'kitchen'" I don't think so, someone else would have to give a definitive answer -- Mike Conley On Wed, Jun 17, 2009 at 10:14 AM, allen.fowler wrote: > > > > 3) Can this relation's objects be

[sqlalchemy] Re: relation error?

2009-06-17 Thread Mike Conley
now room is a pointer to a room object identified in the database by room_id and u.room = r will work OK -- Mike Conley On Wed, Jun 17, 2009 at 2:44 AM, AF wrote: > > I'm probably just missing something... here is my code: > > engine = create_engine('sqlit

[sqlalchemy] Re: Problem getting primary key on object creation

2009-06-15 Thread Mike Conley
Since the id will only be available after a database insert; some flavor of session.flush() is needed. I like to keep object constructors limited to actual object construction; so putting it in get_person() after instantiating the person seems best approach. -- Mike Conley On Mon, Jun 15

[sqlalchemy] Re: Formatting return of 'query'

2009-06-09 Thread Mike Conley
and return it; only a pointer to the list is being returned. The list is not copied to another memory location unless the caller does that themselves, and they should be working with and understand the same memory constraints you are dealing with. -- Mike Conley On Mon, Jun 8, 2009 at 11:34

[sqlalchemy] Re: insert statment

2009-06-09 Thread Mike Conley
g'),) insdata = [dict(zip(cols,datum)) for datum in data] conn.execute(dept.insert(), insdata) ## or in a single statement ## conn.execute(dept.insert(), [ dict(zip(('deptid','deptname',), datum)) for datum in ( (31,'Sales'), (33,'Enginee

[sqlalchemy] Re: ForeignKey not saved - sqlite3, TG1.1

2009-06-07 Thread Mike Conley
where you expect it to. The revised code says "append a Blog to the already existing list in user.blogs". This causes SQLAlchemy to issue an insert adding a new row to the blog table, and no updates to prior existing blog records. -- Mike Conley On Sat, Jun 6, 2009 at 11:56

[sqlalchemy] Re: ForeignKey not saved - sqlite3, TG1.1

2009-06-06 Thread Mike Conley
Looks like the culprit is: user.blogs = [Blog(title=input['blog_title'] this replaces your user.blogs relation with a single entry list containing the last Blog try this to add a Blog to the relation list user.blogs.append(Blog(title=input['blog_title')) -- Mike Conley

[sqlalchemy] Re: "Underscore tables" - odd table renaming

2009-06-05 Thread Mike Conley
could be something in SQL generation. -- Mike Conley On Fri, Jun 5, 2009 at 6:15 AM, outlier wrote: > > I'm not even sure where to start studying this problem but here goes: > I have an application that uses a MySQL db wrapped with SA and it > works fine. While writing n

[sqlalchemy] Re: Relation spanning multiple tables

2009-06-02 Thread Mike Conley
This looks like an association proxy. Have you tried that? http://www.sqlalchemy.org/docs/05/reference/ext/associationproxy.html -- Mike Conley On Mon, Jun 1, 2009 at 11:46 PM, George Sakkis wrote: > > I can't for the life of me figure out how to specify a relation > spanni

[sqlalchemy] Schema compare utility

2009-05-29 Thread Mike Conley
I need to compare database schemas (tables, column names, types, constraints, etc.). Is there anything out there that uses SQLAlchemy metadata to compare database schemas? or should I start working on one? -- Mike Conley --~--~-~--~~~---~--~~ You received this

[sqlalchemy] Re: Query.delete() doesn't cascade on Sqlite

2009-05-29 Thread Mike Conley
Harish said it was an embedded system, probably all resources are pretty severely restricted. -- Mike Conley On Fri, May 29, 2009 at 9:44 AM, Randy Syring wrote: > > Mike, > > Well...I am not sure. I thought SQLite held transaction details in > a .journal file and not in mem

[sqlalchemy] Re: Query.delete() doesn't cascade on Sqlite

2009-05-29 Thread Mike Conley
igger. -- Mike Conley On Fri, May 29, 2009 at 8:47 AM, Randy Syring wrote: > > Another solution is to use triggers in SQLite to enforce FK > relationships. > > http://www.sqlite.org/cvstrac/wiki?p=ForeignKeyTriggers > http://code.google.com/p/sqlitefktg4sa/ > > On May 29

[sqlalchemy] Re: Query.delete() doesn't cascade on Sqlite

2009-05-29 Thread Mike Conley
session.commit() if count > 0: session.commit() # this gets the last group of deletes The disadvantage of this approach is that you lose the ability to rollback the entire delete process, and now must handle that problem with application design. -- Mike Conley On Fri, May 29, 2009 at 4:08

[sqlalchemy] Re: Questions on SQLA Queries

2009-05-27 Thread Mike Conley
ush() session.commit() -- Mike Conley On Wed, May 27, 2009 at 9:13 AM, Gregg Lind wrote: > > I believe by "map function", Timothy may be implying that you should > use any of the python idioms for converting iterables of tuples to a > straight tuple. The one I like best > &

[sqlalchemy] Re: Questions on SQLA Queries

2009-05-27 Thread Mike Conley
ptimizing this delete process. -- Mike Conley On Wed, May 27, 2009 at 7:25 AM, Harish Vishwanath wrote: > Thanks! > > Could you elaborate on how you use the map function? I couldn't find it > myself in the docs. > > Regards, > Harish > > > > On Wed, May

[sqlalchemy] Re: Performance

2009-05-26 Thread Mike Conley
On Tue, May 26, 2009 at 5:11 AM, Marcin Krol wrote: > > > What I do not get is why after this query takes place, SQLA runs a lot > those small queries - I included all (most?) the necessary columns in > the big initial query, so Host data should be filled in by SQLA eager > loading (which is defa

[sqlalchemy] Re: I can't delete SQLite db file

2009-05-15 Thread Mike Conley
I found that you need to call eng.dispose() to disconnect from the database before deleting the file. Not sure about what is happening under the covers at that point, but it seems to work. -- Mike Conley On Fri, May 15, 2009 at 1:35 PM, RusPython wrote: > > Hi guys, > > I ha

[sqlalchemy] Re: Querying with ORM - 2 foreign keys

2009-05-07 Thread Mike Conley
like the query.join() documentation describes. The problem is how to express a single join when it depends on 2 foreign keys to 2 different targets. Am I missing something, or do I always have to use a SQL expression in this case? -- Mike Conley On Thu, May 7, 2009 at 1:34 PM, Michael

[sqlalchemy] Re: last_inserted_ids and ORM

2009-05-07 Thread Mike Conley
Ahh yes, I use autoflush almost exclusively and forget that you can separate the flush() and commit(). -- Mike Conley On Tue, May 5, 2009 at 6:31 PM, Michael Bayer wrote: > > Mike Conley wrote: > > Does the idea of last_inserted_ids exist for ORM? > > > > I do >

[sqlalchemy] Querying with ORM - 2 foreign keys

2009-05-07 Thread Mike Conley
attributes, but I can't figure out the syntax when 2 foreign keys are present. http://www.sqlalchemy.org/docs/05/reference/orm/query.html?highlight=#sqlalchemy.orm.query.Query.join A full example can be found at http://pastebin.com/m120d486a -- Mike Conley --~--~-~--~~~

[sqlalchemy] last_inserted_ids and ORM

2009-05-05 Thread Mike Conley
: result = conn.execute(table.insert(etc.. I can directly access the inserted id as result.last_inserted_ids() without another database call. Can I get the id directly when using the ORM? -- Mike Conley --~--~-~--~~~---~--~~ You received this

[sqlalchemy] Re: obtaining a table schema

2009-04-29 Thread Mike Conley
Look at the primary_key attribute of the table instance. uu = Table('u',meta, Column('id',Integer,primary_key=True), Column('data',Integer)) print uu.primary_key.columns ['u.id'] Mike On Tue, Apr 28, 2009 at 7:53 PM, Paul Rigor (gmail) wrote: > Hi gang, > I've recently started

[sqlalchemy] Re: Create table from declarative class definition.

2009-04-26 Thread Mike Conley
) class CST_LEVEL(Base): etc... or (2) access the internal metadata directly Base = declarative_base() class CST_LEVEL(Base): etc... Base.metadata.create_all() -- Mike Conley On Sun, Apr 26, 2009 at 2:07 AM, Paul Hemans wrote: > > Hi Newbie here, > If, using the declarative

[sqlalchemy] Re: puzzling outerjoin in the mapper

2009-04-22 Thread Mike Conley
problem. -- Mike Conley On Sun, Apr 19, 2009 at 2:45 PM, Alessandro Dentella wrote: > > Hi, > > i'm playing with outerjoin defined in the mapper. I'm getting results > different from what I expected, so that I would like to understand which is > the underline logic. &g

[sqlalchemy] Re: Numeric() type behavior

2009-04-13 Thread Mike Conley
wiki. Maybe I'll look at that as an exercise. -- Mike Conley On Mon, Apr 13, 2009 at 1:27 PM, Michael Bayer wrote: > > Its possible that SQLite doesn't respect the "scale" argument. I'd look > at the full SQL generated to ensure its what you'd expect, then

[sqlalchemy] Re: Query with outer join and function

2009-04-10 Thread Mike Conley
This will teach me to run a test it first, I don't think this is exactly right, but it should be close. -- Mike Conley On Fri, Apr 10, 2009 at 9:43 AM, Mike Conley wrote: > Try this, has one nested query > sub = session.query(C.id.label('c_id'), >

[sqlalchemy] Re: Query with outer join and function

2009-04-10 Thread Mike Conley
in q: print 'D-id:%s C-id:%s C-max:%s'%(row.id, row.c_id, row.c_maxvalue) -- Mike Conley On Fri, Apr 10, 2009 at 8:55 AM, Joril wrote: > > On 10 Apr, 12:52, a...@svilendobrev.com wrote: > > that's what i have in bitemporal queries. > > u need a groupby and

[sqlalchemy] Re: moving an object

2009-04-06 Thread Mike Conley
roperly encapsulates inserting and removing the entry in a single operation. I can imagine that there would be many variations on business rules for moving an item that would be difficult to encapsulate in a common operation within SA. -- Mike Conley On Mon, Apr 6, 2009 at 2:10 AM, jean-ph

[sqlalchemy] Re: Insertion issues

2009-04-03 Thread Mike Conley
conn = eng.connect() conn.execute(users.insert(), [{'name':'joe', '10:00':'1200'}]) -- Mike Conley On Fri, Apr 3, 2009 at 12:07 AM, Tanmoy wrote: > Tried that...dosent work > > > > > Tom > > > > -

[sqlalchemy] Re: Filtering a relation

2009-03-27 Thread Mike Conley
tant using the same idea in more complex associations. -- Mike Conley On Fri, Mar 27, 2009 at 11:51 AM, David Gardner wrote: > Try this: > > mapper(Parent, parent_table, properties = { > 'boys':relation(Child, backref='parent', > pri

[sqlalchemy] Filtering a relation

2009-03-26 Thread Mike Conley
cify a relation that gives a list of the boys Parent.boys = relation(Child, ??) I suspect it is something pretty straight forward, but can't figure it out -- Mike Conley --~--~-~--~~~---~--~~ You received this message because you are subscr

[sqlalchemy] Re: 0.5.2 seems to always roll back with mssql

2009-03-20 Thread Mike Conley
Have you tried adding echo=True to the engine to observe the actual SQL? -- Mike Conley On Fri, Mar 20, 2009 at 8:23 PM, davidlmontgomery < davidlmontgom...@gmail.com> wrote: > > I'm using sqlalchemy with sql server express. Client-side > is also Windows, running pyth

[sqlalchemy] Re: Application performance

2009-03-19 Thread Mike Conley
I believe #1 will iterate on the cursor retrieving one object from cursor on each iteration, while #2 retrieves all objects then processes the entire result set in Python. Try changing #1 to use for o in session.query(Object).all() to retrieve all objects before doing the iteration, same as

[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Mike Conley
On Wed, Mar 18, 2009 at 11:00 AM, Michael Bayer wrote: > > Sanjay wrote: > > > > Hi, > > > > I want to write something like > > > > query.filter(BizObj.col.in_("SELECT col FROM some_table")). > > > > Could not find out how to do it. The code on neither the above nor the > > below worked. > > > > q

[sqlalchemy] Re: getting the number of records in a result set from select

2009-03-13 Thread Mike Conley
If you use rows = cursor.fetchall() you have already executed the query and the result is a list of RowProxy's returned by the query. Count then is simply count = len(rows) Otherwise, the count(*) approach is correct. -- Mike Conley On Fri, Mar 13, 2009 at 4:42 PM, jeff

[sqlalchemy] Re: delete multiple objects

2009-02-20 Thread Mike Conley
query has both bulk delete and update methods http://www.sqlalchemy.org/docs/05/reference/orm/query.html#the-query-object count = session.query(Person).filter(... whatever criteria ...).delete(synchronize_session=False) On Fri, Feb 20, 2009 at 5:22 AM, Ids wrote: > > Hello, > > I'm using the

<    1   2