[sqlalchemy] Incorrect DDL generated for server_default

2011-06-09 Thread MikeCo
Server defaults appear to be handled incorrectly in some cases (looks like for string values) in versions 0.6 and 0.7. The code works in 0.5. I run into this with sqlite, and don't have access other databases right now. Test case (code below): 1. create a table with server side default value (I am

[sqlalchemy] Adding meta information to autoloaded objects

2009-03-07 Thread MikeCo
Sometimes we autoload tables that do not have foreign keys specified in the DDL, but need the relations in SQLA. Here are some techniques that seem to work along with my observations. I'm interested finding best approach. We have a parent-child one-to-many relation. The relation will be defined

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread MikeCo
Using an update query with synchronize_session=False will generate a single SQL statement that will be as efficient as possible. Look at this example http://stackoverflow.com/questions/270879/efficiently-updating-database-using-sqlalchemy-orm/270942 and docs http://www.sqlalchemy.org/docs/05/r

[sqlalchemy] Re: classes in separate files

2009-02-09 Thread MikeCo
Here is an example of how we are doing it. http://dpaste.com/hold/118525 separate the big paste into files as indicated by the comments and you should be able to run it. One key is that you need to import the user class into the address.py -- Mike --~--~-~--~~~---~-

[sqlalchemy] Re: Outer joins with ORM and single table polymorphism

2009-02-05 Thread MikeCo
After some experimenting I am able to generate the correct query by two methods (1) build query from ORM classes with ORM session.query() (2) build query from underlying tables with sql expressions I like the ORM based method better, because the code does not need to know which columns ar

[sqlalchemy] Re: Textual SQL

2009-02-02 Thread MikeCo
Commit behavior depends on how you configure the session's autocommit property. Follow the log messages in this little test. from sqlalchemy import MetaData, Table, Column, String from sqlalchemy.orm import sessionmaker meta = MetaData('sqlite:///') Session = sessionmaker(bind=meta.bind) t = Tabl

[sqlalchemy] Re: Outer joins with ORM and single table polymorphism

2009-02-01 Thread MikeCo
Oops, the description should say Inputs are stored in a single table with column "kind" as a discriminator. On Feb 1, 10:58 pm, MikeCo wrote: > I can't figure out how to write this outer join query in ORM-speak. > > Jobs have Steps; Steps have optional inputs of type &q

[sqlalchemy] Outer joins with ORM and single table polymorphism

2009-02-01 Thread MikeCo
I can't figure out how to write this outer join query in ORM-speak. Jobs have Steps; Steps have optional inputs of type "SRC1", "SRC2", or "SRC3". Steps are stored in a single table with column "kind" as a discriminator. The existing legacy code uses a SELECT statement with outer joins to get the

[sqlalchemy] Understanding polymorphism

2009-02-01 Thread MikeCo
I have a single table polymorphism question. It looks like I can't directly set the value of the polymorphic discriminator when creating records; it is only set correctly when you instantiate objects of the derived class. Is that true? Why, or what is wrong here? Here is the scenario: Jobs have

[sqlalchemy] Re: the return type of conn.execute(text(""))

2009-01-28 Thread MikeCo
Doesn't this work? result = conn.execute('some select statement').fetchall() result will be a ResultProxy containing RowProxy's pickleable = [tuple(row) for row in result] Each tuple contains the column data in what should be a pickleable form. This will work for ints, strings, unicodes, etc.

[sqlalchemy] Re: Creating Tables From Selects

2009-01-27 Thread MikeCo
I found this to be an interesting little problem. The task can be accomplished by using the text of a statement to construct a new string then executing. Here is a simple recipe using SQLite. I'm sure it can be extended fairly easily, and should work in any standard SQL environment import sqlal

[sqlalchemy] Bulk insert operation

2009-01-19 Thread MikeCo
I have a use case where detail data is collected during operation then copied periodically to a history table. In SA, tables look something like this: #history data history = Table('history', metadata, Column('id', Integer, primary_key=True), Column('naturalkey', String, unique=True, null

[sqlalchemy] Re: Self-Referential Mapping with Base?

2009-01-12 Thread MikeCo
43 pm, Darren Govoni wrote: > Ahhh, looks like I'm on rc4. Let me try final and see. > > On Sun, 2009-01-11 at 13:10 -0500, Michael Bayer wrote: > > 0.5.0 final ? > > > On Jan 11, 2009, at 12:21 PM, Darren Govoni wrote: > > > > Hi MikeCo, > > >

[sqlalchemy] Re: Self-Referential Mapping with Base?

2009-01-10 Thread MikeCo
eliminates the extra SELECT statement. Inefficiencies like that are pretty rare. On Jan 9, 11:33 pm, MikeCo wrote: > I spent some time understanding this a little while ago. Here is the > construct you need > (thanks to Michael Bayer for making it clear for me) > > # D  self refere

[sqlalchemy] Re: Self-Referential Mapping with Base?

2009-01-09 Thread MikeCo
I spent some time understanding this a little while ago. Here is the construct you need (thanks to Michael Bayer for making it clear for me) # D self referential class D(Base): __tablename__ = 'D' id = Column(Integer, primary_key=True) id_d = Column(Integer, ForeignKey('D.id')) n

[sqlalchemy] Ordering query for a list

2009-01-07 Thread MikeCo
This may not be an SA specific question, but maybe there is an answer here. I have a table that contains data that is actually a linked list. Each record has a previd column that is the id of the previous record in the list. The code to maintain the list exists and works well (a legacy non-SA app

[sqlalchemy] Re: Table has no column named xxxx ??

2008-12-07 Thread MikeCo
Did you run this code more than once, adding the RankProf column between runs? If so, the universities table in data.db database would not have the column RankProf defined. The metadata create_all() method does not replace existing tables. One approach, especially for a test program, is to add a c

[sqlalchemy] Re: inserting

2008-11-26 Thread MikeCo
s convert the dict keys to be   > column.key. > > On Nov 26, 2008, at 5:52 PM, MikeCo wrote: > > > > > Oops, I stand corrected. seehttp://pastebin.com/fe4a38d6 > > > At least for SQLite, my loop solution is many times slower than the > > insert many synta

[sqlalchemy] Re: inserting

2008-11-26 Thread MikeCo
very large numbers of inserts there should be little, if any, noticeable difference. -- Mike On Nov 26, 4:50 pm, MikeCo <[EMAIL PROTECTED]> wrote: > You probably don't want to do the inserts one by one because of the > commit overhead, or needing to rollback on failure of on inser

[sqlalchemy] Re: inserting

2008-11-26 Thread MikeCo
You probably don't want to do the inserts one by one because of the commit overhead, or needing to rollback on failure of on insert. You can still get multiple inserts in one transaction. Add this to the example posted at http://pastebin.com/fd0653b0 to see three inserts in one transaction. print

[sqlalchemy] Re: inserting

2008-11-24 Thread MikeCo
fault value for the column (test 3). It only works correct when the key is the string for the unqualified column name (tests 2 and 4). On Nov 24, 10:37 am, "Michael Bayer" <[EMAIL PROTECTED]> wrote: > the actual Column object or its "key" can be placed in the dict. > &

[sqlalchemy] Re: inserting

2008-11-24 Thread MikeCo
; work in the dictionary definition? -- Mike On Nov 23, 8:58 am, MikeCo <[EMAIL PROTECTED]> wrote: > Your dictionary key CartItemTable.c.colname is an instance of class > Column, The dictionary keys need to be strings. Use str > (CartItemTable.c.colname) to get

[sqlalchemy] Re: inserting

2008-11-23 Thread MikeCo
Your dictionary key CartItemTable.c.colname is an instance of class Column, The dictionary keys need to be strings. Use str (CartItemTable.c.colname) to get the string name of the column and it should work. >>> CartItemTable.c.userId Column('userId', Integer(), ForeignKey('User.userId'), table=,

[sqlalchemy] import sqlalchemy.sql changes __name__

2008-11-22 Thread MikeCo
Why does this change __name__? >>> print __name__ __main__ >>> from sqlalchemy.sql import * >>> print __name__ sqlalchemy.sql It is often bad practice to import *, but still a module should not impact __name__ unless really necessary. Primary side effect is you can no longer use if __name__ ==

[sqlalchemy] Re: declarative and self-referential table

2008-11-11 Thread MikeCo
larative it would look like   > "remote_side=id".   > Seehttp://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relatio... >   for information on this. > > On Nov 11, 2008, at 2:15 PM, MikeCo wrote: > > > > > I have a table that defines a self-

[sqlalchemy] declarative and self-referential table

2008-11-11 Thread MikeCo
I have a table that defines a self-referential hierarchy. My problem is figuring out how to specify that relationship in declarative syntax. From reading the documentation and looking at example basic_tree.py, I think I understand it when using tables and mappers, but can't get it right with decla

[sqlalchemy] declarative, autoload and late binding to engine

2008-11-06 Thread MikeCo
I have an application that will need to bind to several different databases with the same structure. The databases to be accessed are not known at import time, that will be determined later while the application is running. I want to use declarative and autoload the columns. Autoload needs a data