Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3vq1-0003Aa-Ox for pgsql-general@arkaria.postgresql.org; Mon, 16 Oct 2017 03:13:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e3vq1-0000ZS-Bg for pgsql-general@arkaria.postgresql.org; Mon, 16 Oct 2017 03:13:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e3vnY-0003Tz-IR for pgsql-general@postgresql.org; Mon, 16 Oct 2017 03:10:36 +0000 Received: from mail-pf0-x22e.google.com ([2607:f8b0:400e:c00::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e3vnQ-0002OO-F0 for pgsql-general@postgresql.org; Mon, 16 Oct 2017 03:10:36 +0000 Received: by mail-pf0-x22e.google.com with SMTP id t188so12260917pfd.10 for ; Sun, 15 Oct 2017 20:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lucee-org.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=5krO+gPdst1Z/C1t6kF9MH/bMvS5ha3xsU2c9iysxRg=; b=kwkf1KoG4cB3zPtP/6/wl5dmLcQeo+j9ac6QLm9oBxOF1+0UrQ1kTTxkVrn8epeeDw 9bUMrWcmSAuQxvHpVDbvlqsacNGI/1dnUlm1qiSv2k76wEJWFHJbIO1AqSiIV9Ym0sn5 HMHddTqUzHamvqexDaiaNqgcFlnsT2aQfz8TBFVUmZFqr2yGO/XbLNF/IpZRuQCRr/Ix NFiif4kaTlQXgjsVlQDGzhOni84YXxmkAzfn58UIVRC1FIoAcj+67hLl+q+XhZhNl8o3 1OFk/5wstPoio+4cqbnk9gMll6Cmyd0rOip2GCRCWKVCbEmw5+LwwzadgPQvCUzshI/n TlTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=5krO+gPdst1Z/C1t6kF9MH/bMvS5ha3xsU2c9iysxRg=; b=BLkYMcs6b/Du530k73ygAytZ/amvcw8x8V0pii27dd8LpNOlOqO5e2td44bGvM9GO9 miR2UjfKjVAvq0vRj6XgHGWyUBh1zXuRlV5sW1ZTlBWBrUCZQttJvRJHEqCT73NYyJpk C8B3V0hGkykMJMoxuBnvIZcZ9pM2ol5ukxrholsvMrV9PoCS/VbpBNZBKonz3LeG56l9 akjYigwwl+Nmp5Gj8qAg8BtiG2/mRgEWuwPRS6d70t6+u2GKDCOo3qXI15IAa817Q4oX ltnH3H+4IdPkY4ts6ycELI5vtw+A/sOtQRl/oCuC5X7C8D+pz5CGgUgs323eTtQLvy2O JymA== X-Gm-Message-State: AMCzsaUP2mNNGDNVFFt4DLIaRXAK+/Bqnt+WQtOAtgVSpFovLT3I3wS1 /IvgSiaXL56hYA9nUQgLtIzwQhFL X-Google-Smtp-Source: AOwi7QBnbrA79a0HSN066xpTKcCIqsG7H9LyTSbHt2c48Wd2PPo5BN5aBo04N8E2/H+WlYpqafx15w== X-Received: by 10.101.75.201 with SMTP id p9mr7179705pgr.281.1508123425344; Sun, 15 Oct 2017 20:10:25 -0700 (PDT) Received: from [192.168.1.15] (45-19-167-161.lightspeed.irvnca.sbcglobal.net. [45.19.167.161]) by smtp.googlemail.com with ESMTPSA id q77sm13353791pfd.84.2017.10.15.20.10.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Oct 2017 20:10:24 -0700 (PDT) Subject: Re: Adding identity column to a non-empty table To: pgsql-general References: <37b3858b-0d61-0268-69cc-ff1868ac5255@lucee.org> <7435ef5f-f662-15f0-6ebc-b4b1b7cf1156@lucee.org> <19fb9f81-ebb4-8e0a-24d3-c4aa1630eda3@lucee.org> From: "Igal @ Lucee.org" Message-ID: <959f28ef-4245-8349-eff9-0ff5f666df03@lucee.org> Date: Sun, 15 Oct 2017 20:10:22 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------04CB2CD11A4C9C7D29B5D775" Content-Language: en-US List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org This is a multi-part message in MIME format. --------------04CB2CD11A4C9C7D29B5D775 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 10/15/2017 6:42 PM, Melvin Davidson wrote: > On Sun, Oct 15, 2017 at 9:09 PM, 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 --------------04CB2CD11A4C9C7D29B5D775 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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> 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

--------------04CB2CD11A4C9C7D29B5D775--