SQL statement to set next serial value to max of a table?

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: SQL statement to set next serial value to max of a table?
Date: 2002-08-07 23:01:57
Message-ID: 3D51A6E5.3090207@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I want to execute the following two pseudo-SQL statements (that set the
current value in a serial as the max of the primary key) as one SQL
statement. What is the proper syntax?

1- MAX = select max(id) from T;
2- SELECT setval('T_id_seq', MAX);

Jc

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Seidman 2002-08-07 23:02:31 Re: transactions, serial ids, and JDBC
Previous Message Neil Conway 2002-08-07 22:45:37 Re: transactions, serial ids, and JDBC