dont compile() the insert statement yourself here; since you are only  
executing it once, theres nothing to be gained by manually compiling  
first.  Its also the source of the error. the issue is that when the  
Insert is compiled with no "values" clause, it produces column  
entries for all three columns; but youre only sending two columns in  
your argument list.  this behavior is the same in 0.3.

to compile the insert for just two columns (which again, you probably  
dont need to do here), put them in the "values" clause:

c = Insert(values={'x':bindparam('x'), 'y':bindparam('y')}).compile()
engine.execute(c, {'x':5, 'y':7})



On Aug 23, 2007, at 10:16 AM, che wrote:

>
> Hi,
>
> i tried suggested in other thread way of inserting many records into
> database table and it raised exception against postgres (psycopg2)
> using the latest trunk (r3412) of SA. Then i checked that in version
> 0.3.10 same(analogical) code works. Please tell me if there is
> something wrong with my usage of the 0.4 version of SA if this is not
> a bug.
>
> regards,
> stefan
>
> the sample code is below:
> ###----------------------------
> from sqlalchemy import *
> from sqlalchemy.orm import *
> #db_sqlite = create_engine( 'sqlite:///testdb.db', echo =True )
> if 10:
>     import os
>     try:
>         r = os.system( 'dropdb testdb')
>         r = os.system( 'createdb testdb')
>     except OSError: pass
> db_postgres = create_engine( 'postgres:///testdb', echo =True )
>
> SA_VERSION = '0.4'
> def checkWith( db):
>     if SA_VERSION == '0.3':
>         meta = BoundMetaData( db)
>         meta.engine.echo = 1
>         table_Manager = Table( 'Manager', meta,
>             Column( 'duties', type= String, ),
>             Column( 'name', type= String, ),
>             Column( 'id', Integer, primary_key= True, ),
>         )
>     else:
>         meta = MetaData( db)
>         meta.bind = db
>         meta.bind.echo = 1
>         table_Manager = Table( 'Manager', meta,
>             Column( 'duties', type_= String, ),
>             Column( 'name', type_= String, ),
>             Column( 'id', Integer, primary_key= True, ),
>         )
>     meta.create_all()
>
>     con = db.connect()
>     isql = table_Manager.insert().compile()
>     r2 = con.execute( isql, [
>         dict( name= 'torencho', duties= 'bany'),
>         dict( name= 'mnogoVojdMalkoIndianec', duties= 'lany'),
>     ])
>     r2 = r2.last_inserted_ids()
>     print 'R2: %(r2)s\n' % locals()
>
> #checkWith( db_sqlite)
> checkWith( db_postgres)
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to