Re: Setting Sequence Values

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Martin <martin(at)cornhobble(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Setting Sequence Values
Date: 2007-12-22 01:10:55
Message-ID: 20071221171055.5082a107@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 21 Dec 2007 23:57:21 -0000
Martin <martin(at)cornhobble(dot)com> wrote:

> After porting tables and data from FrontBase I now find that I
> need to update all the values for the sequences that were created
> to reflect the data in the tables. Is there an easy way to do
> this?

Take a look at setval.

postgres=# select setval('foo_id_seq',(select max(id) from foo));
setval
- --------
100
(1 row)

postgres=# select currval('foo_id_seq');
currval
- ---------
100
(1 row)

Sincerely,

Joshua D. Drake

>
>
> ---------------------------(end of
> broadcast)--------------------------- TIP 5: don't forget to increase
> your free space map settings
>

- --
The PostgreSQL Company: Since 1997, http://www.commandprompt.com/
Sales/Support: +1.503.667.4564 24x7/Emergency: +1.800.492.2240
Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
SELECT 'Training', 'Consulting' FROM vendor WHERE name = 'CMD'

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHbGQhATb/zqfZUUQRAkGqAJ9jJMF/1aYY8q7L4C35ogVnSsowAACgnwH3
J0HpPengi7eo4n4b+YLaCZA=
=uQZ6
-----END PGP SIGNATURE-----

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Williamson 2007-12-22 01:14:43 Re: Setting Sequence Values
Previous Message Martin 2007-12-21 23:57:21 Setting Sequence Values