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
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
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
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
--~--~-~--~~~---~-
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
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
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
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
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
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.
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
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
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,
> > >
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
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
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
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
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
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
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
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.
>
&
; 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
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=,
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__ ==
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-
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
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
27 matches
Mail list logo