Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B13E34760AD; Wed, 4 Dec 2002 10:44:32 -0500 (EST) Received: from rh72.home.ee (adsl1030.estpak.ee [213.168.29.11]) by postgresql.org (Postfix) with ESMTP id 6E1F247641A; Wed, 4 Dec 2002 10:43:43 -0500 (EST) Received: from rh72.home.ee (localhost.localdomain [127.0.0.1]) by rh72.home.ee (8.12.5/8.12.5) with ESMTP id gB4Fg1Ee002799; Wed, 4 Dec 2002 20:42:01 +0500 Received: (from hannu@localhost) by rh72.home.ee (8.12.5/8.12.5/Submit) id gB4Fg06W002797; Wed, 4 Dec 2002 20:42:00 +0500 X-Authentication-Warning: rh72.home.ee: hannu set sender to hannu@tm.ee using -f Subject: Re: [HACKERS] how to alter sequence. From: Hannu Krosing To: Oliver Elphick Cc: raja kumar thatte , "pgsql-hackers@postgresql.org" , pgsql-admin@postgresql.org In-Reply-To: <1039010812.11433.75.camel@linda.lfix.co.uk> References: <20021204122900.96540.qmail@web20608.mail.yahoo.com> <1039010812.11433.75.camel@linda.lfix.co.uk> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: Message-Id: <1039016518.2281.17.camel@rh72.home.ee> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.0 Date: 04 Dec 2002 20:41:59 +0500 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/126 X-Sequence-Number: 6621 Oliver Elphick kirjutas K, 04.12.2002 kell 19:06: > On Wed, 2002-12-04 at 12:29, raja kumar thatte wrote: > > Hai friends, > > I have a sequence called raj_seq with max value 3000. > ... > > now i wanted to increase the max value of the raj_seq > > to 9999999. > > How to do this change? > > If i drop and recreate the raj_seq, then i have to > > recreate the table and all triggers working on that > > table.But it is not an acceptable solution. > > So with out droping raj_seq , how do I solve this > > problem. > > Unfortunately there doesn't seem to be any easy way to do this. There > is no ALTER SEQUENCE command and you can't use UPDATE on a sequence. > > Hackers: Could this be a TODO item for 7.4? This seems to work - as an example why we need the TODO ;) hannu=# update seq set max_value = 99; ERROR: You can't change sequence relation seq hannu=# update pg_class set relkind = 'r' where relname = 'seq'; UPDATE 1 hannu=# update seq set max_value = 99; UPDATE 1 hannu=# update pg_class set relkind = 'S' where relname = 'seq'; UPDATE 1 hannu=# select * from seq; sequence_name | last_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called ---------------+------------+--------------+-----------+-----------+-------------+---------+-----------+----------- seq | 1 | 1 | 99 | 1 | 1 | 1 | f | f (1 row) I can't really recommend it, because it may (or may not ;) have some unwanted behaviours as well; > > The easiest way to do this at present is probably to dump the database, > edit the dump to change the sequence max_value and then recreate the > database from the edited dump. I presume you used CREATE SEQUENCE in > order to get such a low max_value. If it were created from a SERIAL > datatype, you would also have to edit the table definition to use a > pre-created sequence. There is no means of specifying a max_value using > SERIAL. -- Hannu Krosing