pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Igal @ Lucee.org <igal@lucee.org>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Adding identity column to a non-empty table
Date: Sun, 15 Oct 2017 20:10:22 -0700
Message-ID: <959f28ef-4245-8349-eff9-0ff5f666df03@lucee.org> (raw)
In-Reply-To: <CANu8Fiwh9SxM5t4BwFr=5F2iD6BW5zY4-o6FRgHHkK79g80ENg@mail.gmail.com>
References: <37b3858b-0d61-0268-69cc-ff1868ac5255@lucee.org>
	<7435ef5f-f662-15f0-6ebc-b4b1b7cf1156@lucee.org>
	<CANu8Fizi9KmxeYe=7C5v81gfUKB00egCrw4axvkOmpox5EeeJQ@mail.gmail.com>
	<19fb9f81-ebb4-8e0a-24d3-c4aa1630eda3@lucee.org>
	<CANu8Fiwh9SxM5t4BwFr=5F2iD6BW5zY4-o6FRgHHkK79g80ENg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>

On 10/15/2017 6:42 PM, Melvin Davidson wrote:
> On Sun, Oct 15, 2017 at 9:09 PM, Igal @ Lucee.org <igal@lucee.org 
> <mailto:igal@lucee.org>> wrote:
>
>     Melvin,
>
>     On 10/15/2017 5:56 PM, Melvin Davidson wrote:
>>
>>         On 10/15/2017 4:01 PM, Igal @ Lucee.org wrote:
>>
>>
>>             Hello,
>>
>>             I'm trying to add an identity column to a table that has
>>             records (previously had a bigserial column which I removed):
>>
>>
>>         There is probably a better solution, but the one I came up
>>         with is to add the column as BIGSERIAL and DROP the SEQUENCE
>>         CASCADE, SELECT the max(rid) + 1, and then convert the column
>>         to IDENTITY:
>>
>>
>>     The correct way to make r_id the primary key would be:
>>
>>     ALTER TABLE  event_log
>>       ADD COLUMN r_id SERIAL;
>>
>>     ALTER TABLE  event_log
>>       ALTER COLUMN r_id TYPE BIGINT,
>>       ADD CONSTRAINT dummy_pk PRIMARY KEY (r_id);
>>
>>     That automatically generates the column as
>>
>>     r_id bigint NOT NULL DEFAULT nextval('dummy_r_id_seq'::regclass),
>>       CONSTRAINT dummy_pk PRIMARY KEY (r_id)
>>
>>     and creates the appropriate sequence for you.
>>
>
>     Does that use the new IDENTITY construct that was added in
>     Postgres 10?  I do not really care for the PRIMARY KEY
>     constraint.  I just want the sequence with the benefits of the new
>     IDENTITY "type".
>
>
> > Does that use the new IDENTITY construct that was added in Postgres 10?
>
> I cannot say, as I do not yet have PostgreSQL 10 installed because it 
> was very recently released.
> However, the method I supplied works for all prior versions of PostgreSQL.

Understood.  But I already had a an auto-increment column by way of 
BIGSERIAL.

I want specifically to use the new IDENTITY feature of Postgres 10.

Best,

Igal Sapir
Lucee Core Developer
Lucee.org <http://lucee.org/;

view thread (7+ messages)  latest in thread

Message-ID: <959f28ef-4245-8349-eff9-0ff5f666df03@lucee.org>
Permalink:  ../959f28ef-4245-8349-eff9-0ff5f666df03@lucee.org/
Also on:    postgresql.org/message-id/959f28ef-4245-8349-eff9-0ff5f666df03@lucee.org

 · 

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: igal@lucee.org
  Subject: Re: Adding identity column to a non-empty table
  In-Reply-To: <959f28ef-4245-8349-eff9-0ff5f666df03@lucee.org>
  References: <37b3858b-0d61-0268-69cc-ff1868ac5255@lucee.org> <7435ef5f-f662-15f0-6ebc-b4b1b7cf1156@lucee.org> <CANu8Fizi9KmxeYe=7C5v81gfUKB00egCrw4axvkOmpox5EeeJQ@mail.gmail.com> <19fb9f81-ebb4-8e0a-24d3-c4aa1630eda3@lucee.org> <CANu8Fiwh9SxM5t4BwFr=5F2iD6BW5zY4-o6FRgHHkK79g80ENg@mail.gmail.com> <959f28ef-4245-8349-eff9-0ff5f666df03@lucee.org>

* 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