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-general(at)lists(dot)postgresql(dot)org
Subject: Re: Reset sequence to current maximum value of rows
Date: 2024-06-13 22:01:23
Message-ID: 4f319e27-0e54-40dd-888f-1e4c856a1b02@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/13/24 12:57, Rich Shepard wrote:
> On Thu, 13 Jun 2024, David G. Johnston wrote:
>
>> Because you specified company_name in the column listing for the things
>> you are inserting values for. So in column position 2 you must have a
>> value than can be inserted into the company_name column. It is utterly
>> immaterial how you specified the value for column position 1.
>
>> We can't help you understand if you don't show a complete working example
>> and ask a question in relation to that example.  I suggest you start from
>> scratch, this time using scripts, so that your work is recorded and
>> replayable.
>
> David,
>
> INSERT into companies (company_nbr,company_name,industry,status) VALUES
> (DEFAULT,'A new company name', 'Manufacturing',DEFAULT);
>
> I always write scrips for SQL, R, GRASS, Python, bash. Above is a redacted
> version of the single name I tried adding to the companies table.
>
> Yesterday, before learning to use DEFAULT for the company_nbr PK I entered
> all rows using company_nbr 2342-2391. This morning, after running the

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?

> single-line INSERT command company numbers from 2341-2392 all had 'A new
> company name' as the company_name.
>
> HTH,
>
> Rich
>
>

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2024-06-13 22:13:37 Re: Reset sequence to current maximum value of rows
Previous Message Rich Shepard 2024-06-13 21:13:26 Re: Reset sequence to current maximum value of rows