update table sequence

Поиск
Список
Период
Сортировка
Искать

update table sequence

От:
e.ellenkamp@copernicus-it.nl (Egbert Ellenkamp)
Дата:
All,

Is there a way I can set the sequence of a table equal to highest row
ID?
For example something like:
select setval('mytable_myrowid_seq',select max(myrowid) from mytable);

I read the documentation but could not find anything relevant.

Thanks in advance,

Egbert.

Re: update table sequence

От:
"Ross J. Reedstrom" <reedstrm@rice.edu>
Дата:
On Fri, Mar 16, 2001 at 12:15:28PM +0000, Egbert Ellenkamp wrote:
> All,
> 
> Is there a way I can set the sequence of a table equal to highest row
> ID?
> For example something like:
> select setval('mytable_myrowid_seq',select max(myrowid) from mytable);

So close!

select setval('mytable_myrowid_seq',max(myrowid)) from mytable;

Ross

Re: update table sequence

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
e.ellenkamp@copernicus-it.nl (Egbert Ellenkamp) writes:
> select setval('mytable_myrowid_seq',select max(myrowid) from mytable);

That should work if you put in the required parentheses around the
sub-select:

select setval('mytable_myrowid_seq', (select max(myrowid) from mytable));
		regards, tom lane

FAQ