From 787a7b864bbecb650608fe16346cbe8a47a8efaf Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Fri, 19 Oct 2012 13:35:05 -0700 Subject: [PATCH] Make reset-postgresql-sequences work on empty tables --- bin/reset-postgresql-sequences | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/reset-postgresql-sequences b/bin/reset-postgresql-sequences index c5e3777..7c18ba7 100755 --- a/bin/reset-postgresql-sequences +++ b/bin/reset-postgresql-sequences @@ -33,8 +33,9 @@ for table in sorted(mapped_classes): for c in sequence_columns(table): max_value, = session.query(func.max(c)).one() if options.verbose: - print "%s.%s <- %s" % (table_name, c.name, max_value) + print "%s.%s <- %s" % (table_name, c.name, max_value or 0) session.execute(func.setval( func.pg_get_serial_sequence(table_name, c.name), - max_value, + max_value or 1, + max_value is not None, ))