Re: Reset sequence to current maximum value of rows - Mailing list pgsql-general

From Rich Shepard
Subject Re: Reset sequence to current maximum value of rows
Date
Msg-id b6b331ff-913d-d5d8-905-aba54e90c99f@appl-ecosys.com
Whole thread Raw
In response to Re: Reset sequence to current maximum value of rows  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Reset sequence to current maximum value of rows
Re: Reset sequence to current maximum value of rows
Re: Reset sequence to current maximum value of rows
List pgsql-general
On Thu, 13 Jun 2024, Adrian Klaver wrote:

> Not with:
>
> Table "public.companies"
>
>     [...]
> Indexes:
>    "organizations_pkey" PRIMARY KEY, btree (company_nbr)
>
> That would throw duplicate key errors.
>
> Are you sure that you did not do this on the contacts table as the company FK 
> back to companies?

Adrian,

Yes, I'm sure. Early yesterday I did get duplicate key errors. That's when I
looked on stackexchange to learn how to reset the sequence's max value to
the value of the number of rows in the table. Not only did my attempt to add
a single new company to the companies table change all company names in that
one industry to the new name, but I just discovered that it changed all rows
in that column to the new company name:

  company_nbr |                  company_name 
-------------+-------------------------------------------------
            1 | Markowitz Herbold PC
            2 | Markowitz Herbold PC
            3 | Markowitz Herbold PC
            4 | Markowitz Herbold PC
            5 | Markowitz Herbold PC
            6 | Markowitz Herbold PC
            7 | Markowitz Herbold PC
            8 | Markowitz Herbold PC
            9 | Markowitz Herbold PC
           10 | Markowitz Herbold PC
           11 | Markowitz Herbold PC
           12 | Markowitz Herbold PC
           13 | Markowitz Herbold PC
           14 | Markowitz Herbold PC
           15 | Markowitz Herbold PC
           16 | Markowitz Herbold PC
           17 | Markowitz Herbold PC
           18 | Markowitz Herbold PC
           19 | Markowitz Herbold PC
           20 | Markowitz Herbold PC
           22 | Markowitz Herbold PC
           23 | Markowitz Herbold PC
--More--

So now I need to extract the companies table data from my 2024-06-10 backup
and use that to update the entire table. Sigh. There are 2101 rows in that
table and I must have forgotten to specify industry for that one new
addition. Not like me to do so, but it's the only explanation I have.

It might be quicker for me to restore the entire database from that backup
and then insert all new table rows since I have saved all the scripts.

Regards,

Rich



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Reset sequence to current maximum value of rows
Next
From: Adrian Klaver
Date:
Subject: Re: Reset sequence to current maximum value of rows