Re: Update with function - Mailing list psycopg

From Adrian Klaver
Subject Re: Update with function
Date
Msg-id 4F75D9B0.7060104@gmail.com
Whole thread Raw
In response to Re: Update with function  (egbert <egbert.bouwman@xs4all.nl>)
Responses Re: Update with function  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List psycopg
On 03/30/2012 09:02 AM, egbert wrote:
> On Fri, 2012-03-30 at 06:45 -0700, Adrian Klaver wrote:
>
>> A simple solution that demonstrates one way to do the above:
>>
>>
>> cur.execute("select recno from some_table")
>>
>> for row in cur:
>>     recno = cur[0]
>>     cur.execute("update books set inyear=%s", (makeyear(recno),))
>>
> Thanks for your suggestion, Adrian.
> Actually, that was something I tried first.
> But my some_table is about 165000 records, and it took nearly three
> hours (on my not so young system) to run the individual updates.
> So I looked for a one-pass solution.

Another option is write function in Postgres that does what you want and
call that function.

> egbert
>


--
Adrian Klaver
adrian.klaver@gmail.com

psycopg by date:

Previous
From: egbert
Date:
Subject: Re: Update with function
Next
From: Daniele Varrazzo
Date:
Subject: Re: Update with function