Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHYrT-0005uo-4U for pgsql-general@arkaria.postgresql.org; Fri, 19 Apr 2019 19:07:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hHYrQ-0003cX-HI for pgsql-general@arkaria.postgresql.org; Fri, 19 Apr 2019 19:07:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHYrO-0003cQ-HH for pgsql-general@lists.postgresql.org; Fri, 19 Apr 2019 19:07:44 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHYrM-0001oh-4i for pgsql-general@lists.postgresql.org; Fri, 19 Apr 2019 19:07:41 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 8D96650F; Fri, 19 Apr 2019 15:07:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 19 Apr 2019 15:07:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=e 0IYIucssv3t7Vj2lzShIYs5pC+5VU6SWcIwBkPmf4s=; b=nlFt7OPDUlZqk7Iwn YXPYKdA0v41jiG/yvD2jfby8koa77n4BovoWD1qpwukwn0Va4ZBdxLIQLydvRdVp I276NNzk4qqqqbcx9GMUNov5YD9z5K/j6V+kU/IUXThlQdvJEdXMvh405toLNiJJ gjdQvleGsQHd8glmM4tQ/4n9z282V1ntA+3oTI76qkn9O3THnW7D5/xQIfrypQsD lkJg2JBiLMd/o29ex5S7cZEsXLWpQoTS+WN3jOFmlivnLztSSQ95BWM4TFz8A2tw gtBuhy6Z/QWYLS/MC7B5FIeMdk1SVGRF2PzFYvxS1b5WVS6o6yUMVtpJ+1slNpKh gBy9Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=e0IYIucssv3t7Vj2lzShIYs5pC+5VU6SWcIwBkPmf 4s=; b=jAMkmP8m6M7wxvJypakPjC5ieq/WNlVCRF/C/r0xOxVtc6uA+yH0GHRhh LtGPdJ2aWaKnmh6ulXbU+qEveNEvlV8bU22jc5DjGNp4+GZFRft8qvO9GvKObBlB Xg+WbxsqP/Ya57H/zw2CY4MPGLX85jXARfhOXVxpd/XPia5c2fY/sh9ZHDEal0QX 03OezZD11VObsBOaqZZWHAwHNPktnnij9sQT5YyzsODHLF/8ACioqeRy6Pj/VI05 kU7gKmW25oVRU6A0c8N2UpWMA6C91qNVEmsCYotJ+Q2nz5f7D0EEBUWJFUHuMalO 2LChexlhnEGkDow/2YJkZlf60stvg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrfeekgddviecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecukfhppeejuddrvdduvddrudehtddrvddtvdenucfrrghrrghmpehmrghilhhfrhho mheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvg hrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id C4540E40E3; Fri, 19 Apr 2019 15:07:36 -0400 (EDT) Subject: Re: Primary key data type: integer vs identity To: Ken Tanzer Cc: Rich Shepard , "pgsql-generallists.postgresql.org" References: From: Adrian Klaver Message-ID: Date: Fri, 19 Apr 2019 12:07:36 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/19/19 11:32 AM, Ken Tanzer wrote: > On Fri, Apr 19, 2019 at 11:20 AM Adrian Klaver > > wrote: > > On 4/19/19 11:14 AM, Rich Shepard wrote: > > On Fri, 19 Apr 2019, Adrian Klaver wrote: > > > >> If it is working for you now I see no reason to switch. > > > > Adrian, > > > > It does work. I just learned about the SQL identity type and want > to learn > > when it's most appropriate to use. The databases I develop all > work with > > integers as primary keys and reading about the type didn't > clarify (for me) > > when it should be used. > > Mainly for folks that want cross database SQL compliance. It is not a > type so much as a way of specifying an auto-increment column. > > > It also sounds like it has advantages in terms of tying your sequence > directly to the column.  If you drop a serial column, it doesn't drop > the sequence. Misread your post the first time still: create table serial_test(id serial, fld_1 text); CREATE TABLE test=> \d serial_test Table "public.serial_test" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+----------------------------------------- id | integer | | not null | nextval('serial_test_id_seq'::regclass) fld_1 | text | | | test=> alter table serial_test drop column id; ALTER TABLE test=> \d serial_test Table "public.serial_test" Column | Type | Collation | Nullable | Default --------+------+-----------+----------+--------- fld_1 | text | | | test=> select * from serial_test_id_seq ; ERROR: relation "serial_test_id_seq" does not exist LINE 1: select * from serial_test_id_seq ; > Once I've upgraded to 10+, I might look at converting my existing serial > columns.  Peter Eisentraut wrote a good piece(1) on identity columns, > including a function for converting existing serial columns.  I've > copied the function below, but had two questions about it: > > 1)  Would the function as written also reassign ownership to that table > column?  (I see the update to pg_depend and pg_attribute, but don't know > enough about them to know if that changes ownership) > 2)  Would one have to be a superuser to do this? > > Thanks, > Ken -- Adrian Klaver adrian.klaver@aklaver.com