Re: SQLSoup results and zip

Christopher Clarke <cclarke-wYfHrJ5eQDBWk0Htik3J/[email protected]> Tue, 6 Feb 2007 10:54:35 -0400
Newsgroups gmane.comp.python.spyce.general
Message-ID <[email protected]>
Hi Jonathan

Yes this is what i meant instead of using the engine and going back  
to writing SQL
Here is an example:
------------------------------------------------------
     mydb=SqlSoup('postgres://cclarke:pasword@localhost/a_db')

     start = time.time()
     sql= """select trade_date,high,low,open,close from intraday  
where symbol ='RBTT'"""
     rp = mydb.engine.execute(sql)
     x=zip(*rp.fetchall())
     dates=x[0]
     timer = time.time() - start
     print "Took %0.4f seconds using direct sql with engine"  % (timer)

     start = time.time()
     res=mydb.intraday.select(mydb.intraday.c.symbol=='RBTT',
                                 order_by=[desc 
(mydb.intraday.c.trade_date)])
     dates = [row.trade_date for row in res]

     timer = time.time() - start
     print "Took %0.4f seconds using  mapper"  % (timer)

    results
    Took 0.3234 seconds using direct sql with engine
    Took 1.4522 seconds using  mapper
----------------------------------------------
As expected there was a bit of performance hit in the second instance
But the map has other cool properties that i can use
Regards
Chris



On 5 Feb 2007, at 18:15, Jonathan Ellis wrote:

> On Mon, 5 Feb 2007 15:21:34 -0400, "Christopher Clarke"
> <cclarke-wYfHrJ5eQDBWk0Htik3J/[email protected]> said:
>> Hi All
>> I've taken the plunge and have started porting my database stuff to
>> sqlsoup
>> A problem i've encountered is that sometimes i need to get a "column"
>> from a list or results
>> so i do  a res=zip(*mycur.fetchall()) and res[0] is the first column
>> etc.
>> How do i replicate this in SQLSoup?
>> when i try   for example
>> res=mydb.intraday.select(mydb.intraday.c.symbol=='RBTT',
>>                                       order_by=[desc
>> (mydb.intraday.c.trade_date)])
>> zip(*res)  i get
>> TypeError: zip argument #1 must support iteration
>
> Is something like
>
> [row.columnname for row in res]
>
> what you are looking for?


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642