Re: Reset sequence to current maximum value of rows

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Reset sequence to current maximum value of rows
Date: 2024-06-13 18:54:18
Message-ID: 0f40b8e8-a4a1-4c9b-9c90-7402e9edb628@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/13/24 11:38, Rich Shepard wrote:
> On Thu, 13 Jun 2024, Ron Johnson wrote:
>

> Today I saw that I had missed one new company and entered it using DEFAULT
> for the company_nbr PK. When I looked at that table every company_name that
> I had added yesterday was changed to the one inserted today.

You sure you did not actually do an UPDATE without a WHERE?

>
>> What does your table definition look like?
>
>                                          Table "public.companies"
>     Column    |         Type          | Collation | Nullable
> |                  Default
>
> --------------+-----------------------+-----------+----------+--------------------------------------
>  company_nbr  | integer               |           | not null |
> nextval('companies_org_nbr_seq'::regclass)
>  company_name | character varying(64) |           | not null |
> '??'::character varying
>  url          | character varying(64) |           |          |
>  email        | character varying(64) |           |          |
>  industry     | character varying(24) |           | not null |
> 'Other'::character varying
>  status       | character varying(20) |           | not null |
> 'Opportunity'::character varying
>  comment      | text                  |           |          |
>  ea_nbr       | integer               |           |          | 0
>  ea_amt       | numeric(10,2)         |           |          | 0.00
> Indexes:
>     "organizations_pkey" PRIMARY KEY, btree (company_nbr)
> Foreign-key constraints:
>     "organizations_industry_fkey" FOREIGN KEY (industry) REFERENCES
> industrytypes(ind_name) ON UPDAT
> E CASCADE ON DELETE RESTRICT
>     "organizations_status_fkey" FOREIGN KEY (status) REFERENCES
> statustypes(stat_name) ON UPDATE CAS
> CADE ON DELETE RESTRICT
> Referenced by:
>     TABLE "locations" CONSTRAINT "locations_org_nbr_fkey" FOREIGN KEY
> (company_nbr) REFERENCES companies(company_nbr) ON UPDATE CASCADE ON DELETE
> RESTRICT
>     TABLE "people" CONSTRAINT "people_org_nbr_fkey" FOREIGN KEY
> (company_nbr) REFERENCES companies(c ompany_nbr) ON UPDATE CASCADE ON
> DELETE
> RESTRICT
>
> Rich
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Narek Galstyan 2024-06-13 19:26:00 Reserving GUC prefixes from a non-preloaded DB extension is not always enforced
Previous Message Ron Johnson 2024-06-13 18:50:43 Re: Reset sequence to current maximum value of rows