Skip site navigation (1) Skip section navigation (2)

Update with function

From: egbert <egbert(dot)bouwman(at)xs4all(dot)nl>
To: psycopg(at)postgresql(dot)org
Subject: Update with function
Date: 2012-03-30 10:58:15
Message-ID: 1333105095.6625.14.camel@para.lan (view raw, whole thread or download thread mbox)
Lists: psycopg
I am new to this list, and a fairly unsophisticated user of postgresql
and psycopg.

I try to update one field in all records of a table.
The new value is too complicated for a simple expression, so I thought
about a python function. That function uses another field, recno, from
each record.
My question is: how do I pass that second field to the function.

The relevant parts of my script are now:

define makeyear(nummer):
    # ...
    return value

cur.execute("update books set inyear=%s", (makeyear(recno),))

The error message says that recno is not defined.
Egbert Bouwman  
Keizersgracht 197-II    
1016 DS  Amsterdam      
Tel 0(031)20 6257991


psycopg by date

Next:From: Adrian KlaverDate: 2012-03-30 13:45:35
Subject: Re: Update with function
Previous:From: Federico Di GregorioDate: 2012-03-28 21:30:23
Subject: RELEASE: psycopg 2.4.5

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group