Re: SQL statement to set next serial value to max of a table? - Mailing list pgsql-general

From rolf.ostvik@axxessit.no
Subject Re: SQL statement to set next serial value to max of a table?
Date
Msg-id OFF0063962.06D676A8-ONC1256C0F.001B8289@axxessit.no
Whole thread Raw
In response to SQL statement to set next serial value to max of a table?  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
List pgsql-general
Jean-Christian Imbeault <jc@mega-bucks.co.jp> wrote:

>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);

either
        SELECT setval( 'T_id_seq' , max(id) ) from T;
or
        SELECT setval( 'T_id_seq' , (select max(id) from T) );
should do it

--
Rolf


pgsql-general by date:

Previous
From: "Paul Ogden"
Date:
Subject: Re: transactions, serial ids, and JDBC
Next
From: "Peter Gibbs"
Date:
Subject: Re: transactions, serial ids, and JDBC