Resetting serial type after "delete from table"

From: John Gage <jsmgage(at)numericable(dot)fr>
To: PostgreSQL - General <pgsql-general(at)postgresql(dot)org>
Subject: Resetting serial type after "delete from table"
Date: 2010-05-08 08:11:32
Message-ID: F55C210C-F75C-4D14-8730-5FEBE975A366@numericable.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If I "delete from table", which table contains a serial type field,
and then insert new rows into the table "excluding the [serial] column
from the list of columns in the INSERT statement", the numbers in the
serial column resume where they left off prior to the "delete from
table": 639, 640, 641, 642 for example.

This behavior is totally acceptable, but is it possible to have the
serial column reset itself to 1 following "delete from table" (i.e.
following flushing all the rows from the table)? The only way I can
think to do this is by altering the table by dropping the serial
column and then altering it again by adding a new serial column before
doing the insert. That is only a couple of more lines of script, so I
don't do the work, but is there an easier way?

Thanks,

John

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Leif Biberg Kristensen 2010-05-08 08:30:20 Re: Resetting serial type after "delete from table"
Previous Message Rick Yorgason 2010-05-08 07:03:42 Database design confusing pg_restore, and misc pg_restore issues