pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: David G. Johnston <david.g.johnston@gmail.com>
To: Michael Corey <michael.corey.ap@nielsen.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Identity and Sequence
Date: Fri, 16 Feb 2024 10:16:58 -0800
Message-ID: <640cdb04-d9a0-4ee1-8ae6-a13a29aafcac@aklaver.com> (raw)
In-Reply-To: <CAKFQuwarjmGVfHiSRr3yZ0JAVzBr+qXd+nYgY3N4OBJWHBUrdg@mail.gmail.com>
References: <CAABu8T9rBDauVayWfX9NnK=-nJKPUhX_mNKcEG5gWN3uA9umRg@mail.gmail.com>
	<CAKFQuwZGyW+Gn1_Wa6e5=NtTpsnmVgH=6JV516M8r+J4rjyVHQ@mail.gmail.com>
	<CAABu8T_aAmwcC0d4qKBvqoa0qOgvzsrRHckvg8x_RT2EKqnVdg@mail.gmail.com>
	<CAKFQuwarjmGVfHiSRr3yZ0JAVzBr+qXd+nYgY3N4OBJWHBUrdg@mail.gmail.com>


On 2/16/24 10:10 AM, David G. Johnston wrote:
> On Fri, Feb 16, 2024 at 10:24 AM Michael Corey 
> <michael.corey.ap@nielsen.com> wrote:
>
>     By explicitly making a column an IDENTITY column it is going to
>     make a sequence behind the scenes even if one with a similar name
>     exists.  I tried and it created part_tab_part_id_seq1.  Is there
>     no way to have it use the original part_tab_part_id_seq?
>
>
> No, the fact that there is even a sequence is mostly an implementation 
> detail you shouldn't be concerned with.


Actually you should be concerned with/aware of this detail for the 
reason you state below.

>
>      How do I get the data and the sequence in sync?
>
>
> That would be why the alter table command has a bunch of keywords and 
> values as part of it.  So you can modify the values to be what you need.


 From

https://www.postgresql.org/docs/current/sql-altertable.html

"

|SET /|sequence_option|/|
|RESTART| 
<https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-SET-SEQUENCE-OPTION;

    These forms alter the sequence that underlies an existing identity
    column. /|sequence_option|/ is an option supported by |ALTER
    SEQUENCE|
    <https://www.postgresql.org/docs/current/sql-altersequence.html;
    such as |INCREMENT BY|.

"

You need to know how a sequence works and what can be modified.

>
> David J.
>
-- 
Adrian Klaver
adrian.klaver@aklaver.com

view thread (5+ messages)

Message-ID: <640cdb04-d9a0-4ee1-8ae6-a13a29aafcac@aklaver.com>
Permalink:  ../640cdb04-d9a0-4ee1-8ae6-a13a29aafcac@aklaver.com/
Also on:    postgresql.org/message-id/640cdb04-d9a0-4ee1-8ae6-a13a29aafcac@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, david.g.johnston@gmail.com, michael.corey.ap@nielsen.com
  Subject: Re: Identity and Sequence
  In-Reply-To: <640cdb04-d9a0-4ee1-8ae6-a13a29aafcac@aklaver.com>
  References: <CAABu8T9rBDauVayWfX9NnK=-nJKPUhX_mNKcEG5gWN3uA9umRg@mail.gmail.com> <CAKFQuwZGyW+Gn1_Wa6e5=NtTpsnmVgH=6JV516M8r+J4rjyVHQ@mail.gmail.com> <CAABu8T_aAmwcC0d4qKBvqoa0qOgvzsrRHckvg8x_RT2EKqnVdg@mail.gmail.com> <CAKFQuwarjmGVfHiSRr3yZ0JAVzBr+qXd+nYgY3N4OBJWHBUrdg@mail.gmail.com> <640cdb04-d9a0-4ee1-8ae6-a13a29aafcac@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox