On Apr 17, 2013, at 6:53 AM, Philipp Kraus <[email protected]> wrote:
> Hello, > > I have try to insert some data from a dict into my table and I have used the > description on > http://docs.sqlalchemy.org/en/rel_0_8/core/tutorial.html#insert-expressions > I run this command: > > connect.execute( sqlalchemy.Table( tablename, metadata ).insert().values( > i.keys() ).compile(), **i ) > > A few things. One, your Table has no columns declared. Maybe you've already declared this Table in that MetaData with some columns, in which case it's OK, you're just calling it back up, OK. Otherwise, the Table needs to have at least the columns in which you want to use for your insert() statement. The Table object then gets cached in that MetaData() so if this is really a "throwaway" table object I might want to use lowercase "table(), column()" (from sqlalchemy.sql import table, column). The direct reason for the error here is calling compile() on the Insert() construct - this is compiling it against the default dialect, which is not positional, and as you can see later on the database you're using expects positional bind parameters so that isn't working either. There's no need to call compile() explicitly, the engine/connection does that for you, using the correct dialect and other arguments that are specific to the execute() call. The way "values()" is being called here is also incorrect - "values()" accepts a dictionary, or list of dictionaries, not a list of names. It's not necessary to send the "i" dictionary twice - just the arguments passed to execute() will cause the compilation to be specific to those names: ins = table.insert() conn.execute(ins, **i) -- 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 email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
