Re: Update with function

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: egbert(dot)bouwman(at)xs4all(dot)nl, psycopg(at)postgresql(dot)org
Subject: Re: Update with function
Date: 2012-03-30 16:07:50
Message-ID: CA+mi_8a=yR7wC-mvronn+NUO3FGn=xa0e-b+u0ZBUQDHAyb5yA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Fri, Mar 30, 2012 at 5:05 PM, Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> wrote:
> 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.

Which could also be implemented in Python, via pl/python.

-- Daniele

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message egbert 2012-03-30 17:12:38 Re: Update with function
Previous Message Adrian Klaver 2012-03-30 16:05:04 Re: Update with function