pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
update table sequence
3+ messages / 3 participants
[nested] [flat]

* update table sequence
@ 2001-03-16 12:15  Egbert Ellenkamp <e.ellenkamp@copernicus-it.nl>
  0 siblings, 2 replies; 3+ messages in thread

From: e.ellenkamp@copernicus-it.nl @ 2001-03-16 12:15 UTC (permalink / raw)
  To: pgsql-sql

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.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: update table sequence
@ 2001-03-16 19:58  Ross J. Reedstrom <reedstrm@rice.edu>
  parent: Egbert Ellenkamp <e.ellenkamp@copernicus-it.nl>
  1 sibling, 0 replies; 3+ messages in thread

From: Ross J. Reedstrom @ 2001-03-16 19:58 UTC (permalink / raw)
  To: Egbert Ellenkamp <e.ellenkamp@copernicus-it.nl>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: update table sequence
@ 2001-03-16 20:09  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Egbert Ellenkamp <e.ellenkamp@copernicus-it.nl>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2001-03-16 20:09 UTC (permalink / raw)
  To: e.ellenkamp@copernicus-it.nl; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-03-16 20:09 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-16 12:15 update table sequence Egbert Ellenkamp <e.ellenkamp@copernicus-it.nl>
2001-03-16 19:58 ` Ross J. Reedstrom <reedstrm@rice.edu>
2001-03-16 20:09 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox