[sqlalchemy] Re: Inserting Entry Fastest way

2013-03-11 Thread Russ
On Monday, March 11, 2013 4:56:11 PM UTC-4, Arkilic, Arman wrote: Hi, I am working on a database design that I am required to use lots of tables with one-to-many relationship. As a consequence of the design, I need to insert thousands of entries. I tried session.add(), session.merge,

Re: [sqlalchemy] Re: Inserting Entry Fastest way

2013-03-11 Thread Warwick Prince
Thanks Russ - took a look and found it very interesting indeed. Cheers Warwick On Monday, March 11, 2013 4:56:11 PM UTC-4, Arkilic, Arman wrote: Hi, I am working on a database design that I am required to use lots of tables with one-to-many relationship. As a consequence of the design, I

[sqlalchemy] Re: Inserting new records table with serial primary key in Postgresql using ORM

2011-08-27 Thread dfreedman
Thank you, Michael! The only apparent difference was that HasOIDs was set to TRUE on my table. On your notes: 1. Will do. I've been a exec for a decade and my coding skills/ ability to absorb technical reading has deteriorated severely. For some reason mapper was easier for me to pick up.

[sqlalchemy] Re: inserting

2008-11-26 Thread Petr Kobalíček
So, I can use that way in inserting one row, but can't when inserting multiple rows ? It is correct ? 2008/11/24 Michael Bayer [EMAIL PROTECTED]: oh, right. Column objects only work when you say insert().values(**dict). MikeCo wrote: Using 0.5.0rc4 doesn't seem to do that. or what am I

[sqlalchemy] Re: inserting

2008-11-26 Thread Michael Bayer
Petr Kobalíèek wrote: So, I can use that way in inserting one row, but can't when inserting multiple rows ? It is correct ? you can only use string keys as the arguments to the execute() method. this applies to one row or many. columns as keys can be used for the values argument/generative

[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.

[sqlalchemy] Re: inserting

2008-11-26 Thread MikeCo
Oops, I stand corrected. see http://pastebin.com/fe4a38d6 At least for SQLite, my loop solution is many times slower than the insert many syntax. I would be curious to see results run against different database engines. I don't have quick access to them right now. Still, unless there are very

[sqlalchemy] Re: inserting

2008-11-26 Thread Michael Bayer
executemany() syntax is very efficient and I dont really understand how the column/string thing is that much of an issue other than an small inconvenience and a slight failure of the API to be consistent...all you have to do is convert the dict keys to be column.key. On Nov 26, 2008,

[sqlalchemy] Re: inserting

2008-11-26 Thread MikeCo
And that is what we did in our application before this discussion even started. Don't know what Petr is doing in his. I think it is more of an interesting, mostly academic, discussion about alternative techniques; probably a very low priority issue to the SA code base. On Nov 26, 5:56 pm,

[sqlalchemy] Re: inserting

2008-11-26 Thread Michael Bayer
insert() has had some inconsistencies being reported as of late (like params() ) that i would like to get nailed down. a construct like this shouldn't have any surprises. On Nov 26, 2008, at 6:04 PM, MikeCo wrote: And that is what we did in our application before this discussion even

[sqlalchemy] Re: inserting

2008-11-24 Thread MikeCo
Oops, not quite right. str(table.c.colname) returns 'table.colname, and that doesn't work right as dictionary key. You need col only as dictionary key. http://pastebin.com/fd0653b0 has some tests Interesting question is does SA intend that table.colname work in the dictionary definition? --

[sqlalchemy] Re: inserting

2008-11-24 Thread Michael Bayer
the actual Column object or its key can be placed in the dict. MikeCo wrote: Oops, not quite right. str(table.c.colname) returns 'table.colname, and that doesn't work right as dictionary key. You need col only as dictionary key. http://pastebin.com/fd0653b0 has some tests Interesting

[sqlalchemy] Re: inserting

2008-11-24 Thread MikeCo
Using 0.5.0rc4 doesn't seem to do that. or what am I doing wrong? The test, http://pastebin.com/fd0653b0 , looks like when using the Column object, the values inserted are all None (test 1). When the key is the fully qualified table.column, the value inserted is always the default value for the

[sqlalchemy] Re: inserting

2008-11-24 Thread Michael Bayer
oh, right. Column objects only work when you say insert().values(**dict). MikeCo wrote: Using 0.5.0rc4 doesn't seem to do that. or what am I doing wrong? The test, http://pastebin.com/fd0653b0 , looks like when using the Column object, the values inserted are all None (test 1). When the

[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'),

[sqlalchemy] Re: Inserting custom functions / Sorting Mixed-case fields

2008-05-21 Thread Michael Bayer
On May 21, 2008, at 5:06 PM, EricHolmberg wrote: I'm doing a query and would like to order the results in alphabetical order. However, the column used is mixed case, so the results have all lower-case strings before the upper-case variables. In SQL, I would fix this by using the lower()

[sqlalchemy] Re: Inserting custom functions / Sorting Mixed-case fields

2008-05-21 Thread EricHolmberg
# How do I apply the lower(field) function to the strName column? rows = model.data.query().order_by(strName).all( query.order_by(func.lower(strName)) Thanks Michael - you're a life saver! Somehow, I seemed to have missed the entire section on sqlalchemy.sql.func. For anybody else in the

[sqlalchemy] Re: Inserting a node in basic_tree.py

2007-03-30 Thread Michael Bayer
the treenodes table has no explicit sorting field, so by default it will sort by either the row ID of the table or the primary key field. the only operation that can be issued to the database when you add an item to the list is INSERT, so this will always assemble new nodes as the last element in