Re: Reset sequence to current maximum value of rows
Adrian Klaver <adrian.klaver@aklaver.com>
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Rich Shepard <rshepard@appl-ecosys.com>,
pgsql-general@lists.postgresql.org
Date: 2024-06-13T22:24:51Z
Lists: pgsql-general
On 6/13/24 15:13, Rich Shepard wrote: > 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: BEGIN; <Run query> <Check query results> Then either ROLLBACK; COMMIT; depending on the result of check. > > Regards, > > Rich > > -- Adrian Klaver adrian.klaver@aklaver.com