Thread: Buggered Sequence

Buggered Sequence

From
"Jason C. Wells"
Date:
sequence_name|last_value|increment_by| max_value|min_value|cache_value|is_cycled|is_called
-------------+----------+------------+----------+---------+-----------+---------+---------
people_id_seq|         4|           1|2147483647|        1|          1|f        |t
(1 row)


After I screwed up a pgdump and restore I finally got my data back into
the database. I have one little thing to fix. My sequence should be at
last_value='44'.

I tried to use update set last_value='44' but I wasn't allowed to change
the sequence as jcwells or as the pgsql superuser. How can I fix my
sequence?

Thank You,     | http://students.washington.edu/jcwells/
Jason Wells


Re: [GENERAL] Buggered Sequence

From
Jesse Kipp
Date:
Can you do:

drop sequence people_id_seq
create sequence people_id_seq start 44

?

jesse kipp



"Jason C. Wells" wrote:
>
> sequence_name|last_value|increment_by| max_value|min_value|cache_value|is_cycled|is_called
> -------------+----------+------------+----------+---------+-----------+---------+---------
> people_id_seq|         4|           1|2147483647|        1|          1|f        |t
> (1 row)
>
> After I screwed up a pgdump and restore I finally got my data back into
> the database. I have one little thing to fix. My sequence should be at
> last_value='44'.
>
> I tried to use update set last_value='44' but I wasn't allowed to change
> the sequence as jcwells or as the pgsql superuser. How can I fix my
> sequence?
>
> Thank You,      | http://students.washington.edu/jcwells/
> Jason Wells
>
> ************

Re: [GENERAL] Buggered Sequence

From
"Ross J. Reedstrom"
Date:
Jason -
Jesse's sugestion should work, but there's a setval() function for
this exact use:

SELECT setval('people_id_seq',44);

I usually use it like this:

SELECT setval('"Experiments_ExptID_seq"',max("ExptID")) from "Experiments";

That automatically sets the sequence value to the current max in the table.

Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005

Re: [GENERAL] Buggered Sequence

From
"Jason C. Wells"
Date:
On Sat, 4 Dec 1999, Ross J. Reedstrom wrote:

>Jason -
>Jesse's sugestion should work, but there's a setval() function for
>this exact use:
>
>SELECT setval('people_id_seq',44);
>
>I usually use it like this:
>
>SELECT setval('"Experiments_ExptID_seq"',max("ExptID")) from "Experiments";
>
>That automatically sets the sequence value to the current max in the table.

Hmmm. Thanks for the tip. It looks like I will have to dig a little deeper
into postgres.

Thank You,     | http://students.washington.edu/jcwells/
Jason Wells