Thanks!  I took your advise and some advice for turbogears list....and came
up with this program, just in case anyone has to do the same thing:

#!/usr/bin/env python

import sqlobject
import psycopg2
connection =
sqlobject.connectionForURI("postgres://your_connection_scheme_here")
sqlobject.sqlhub.processConnection = connection

def qa(query):
    print "\tRunnng query: ", query
    return connection.queryAll(query)
    print

tables = qa("select * from information_schema.tables where
table_schema='public' and table_type='BASE TABLE'")

for table in tables:
    table = table[2]
    print "Processing table: ", table
    try:
        maxid = qa("SELECT max(id) FROM %s;" % table)
    except psycopg2.ProgrammingError:
        print "skipping"
    try:
        maxid = maxid[0]
    except TypeError:
        continue
    try:
        maxid = maxid[0]
    except TypeError:
        continue
    if not maxid:
        continue
    print "maxid is: ", maxid
    sequence_name = "%s_id_seq" % table
    qa("SELECT setval('%s', %i);" % (sequence_name, maxid))
    print



On Mon, May 19, 2008 at 1:39 AM, Oleg Broytmann <[EMAIL PROTECTED]> wrote:

> On Mon, May 19, 2008 at 12:37:53PM +0400, Oleg Broytmann wrote:
> >    query = "SELECT setval(%s, %d, 0);" % (sequnce_name, id+1)
>
>    Oops, a bug.
> query = "SELECT setval(%s, %d, false);" % (sequnce_name, id+1)
>                               ^^^^^
>
> Oleg.
> --
>     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
>           Programmers don't die, they just GOSUB without RETURN.
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> sqlobject-discuss mailing list
> sqlobject-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to