[DB-SIG] problem with SELECT

Ian merk@pacificnet.net
Wed, 15 Aug 2001 03:41:59 -0700


At 12:17 PM 8/15/2001 +0200, you wrote:
>On 15 Aug 2001 03:11:53 -0700, Ian wrote:
> > Hey all,
> >
> > i'm trying to write a script that updates a database. I dont seem to have
> > any problems inserting data into the tables.
> >
> > But I'm trying to get the ID for a the records and its not working.
> >
> > I tried using cursor.fetchone and all i get returned is None, and i also
> > tried using cursor.execute and i just get an empty tuple.
> >
> > The sql statement works fine when i go into postgres and run it there.
> >
> > I've tried doing 'SELECT NEXTVAL("id_sequence")' and i also tried 
> something
> > simple like 'SELECT * FROM table'
>
>you should use *both* .execute() and .fetchone(). if 'c' is a cursor,
>you can then do:
>
>         c.execute('SELECT NEXTVAL("id_sequence")')
>         id = c.fetchone()[0]
>
>note that you should wrap the code in a try/except block, to catch
>possible errors.
>
>hope this helps,
>federico
>
>--
>Federico Di Gregorio

Thanks,

That did it :)

Ian