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 1hHaHt-0001Ld-RK for pgsql-general@arkaria.postgresql.org; Fri, 19 Apr 2019 20:39:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hHaHs-00069z-Gi for pgsql-general@arkaria.postgresql.org; Fri, 19 Apr 2019 20:39:08 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHaHq-00069s-K1 for pgsql-general@lists.postgresql.org; Fri, 19 Apr 2019 20:39:08 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHaHl-0006Cu-Rd for pgsql-general@lists.postgresql.org; Fri, 19 Apr 2019 20:39:06 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id C4FEF6CA; Fri, 19 Apr 2019 16:38:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 19 Apr 2019 16:38:59 -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=z bUHORzdK/hZAeM144j8SFjBn6i9Cxodkgx2y/Dob60=; b=l3GhHfjrN0xnB7GyL h4Nh+feHr0b0CrkkciABSJBVezAFUm0xgXxiaFpj6zv4JnyyDVRpU/waL6Q49Qke 4f3P1qLS6SABg4y54j92OkzM1EkaFQuRZv62g6PPbi9kuF480ZueDSttcq6WYqeg 6lbae5XqgLY7bvLR2NsiGdcpQX+G3eN3qFWF2K7IayB3fZvPOg98SBzVz8eQw1rj /k2xKAIPnIcwBwy6NL8zrqJ8glo6PM/omUZ0S/5QS3wmLl1E0f1ynZ+69Ae5QZDN Hif/PBhAKofISBjtqJ1Z7bRneN/ley6rUc9WNzb+J4NDY7jWKTUH2QQ/3rQM/Uo7 KCTZg== 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=zbUHORzdK/hZAeM144j8SFjBn6i9Cxodkgx2y/Dob 60=; b=0nUCY/gMZtAohwa5sHNEjGt6FeW1tUJmi/K1b6k3s4uKyjE3r/nnoOKif LGcgjD7VvPNBdE9paWTjiXxLbCM8Cozk5PGqmt+i+DFdNHFfoq0Zc/EV2yIyXAnb Dk58gQLe6FAuo4mWVMuRXQ68D4UflpOsAQNgccHnYhXhwjjHJ3pHWv0mZcDLpCUl ycJ1BJWw/j0zrSVBObk135SyN0i4TJr8mIIYFusH9eHk7Oii7oHyp2bmalz1OIVM ZlPL6bHtEOIDcATo16F4l8hqa0UbaOBuQUjm5C/8HE8i/48BrpDPnAvjAkoj/5fN urDaIZSw3NUfka2UCfPz6dp/X2qgA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrfeekgdefhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuffhomhgrihhnpegrghgvnhgthidqshhofhhtfigrrhgvrdhorhhgnecukfhppeeh tddrudeljedrkedtrddvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkh hlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 20ECBE4472; Fri, 19 Apr 2019 16:38:57 -0400 (EDT) Subject: Re: Primary key data type: integer vs identity To: Ken Tanzer Cc: Rich Shepard , "pgsql-generallists.postgresql.org" References: <4d387c8e-a261-0734-a10f-dfde7ce538f0@aklaver.com> <2752f2d1-2cec-1df4-21f7-b0b004f8e500@aklaver.com> From: Adrian Klaver Message-ID: <47f1fa10-fb71-0f58-9dcf-c5083680059a@aklaver.com> Date: Fri, 19 Apr 2019 13:38:55 -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 1:02 PM, Ken Tanzer wrote: > On Fri, Apr 19, 2019 at 12:50 PM Adrian Klaver > > wrote: > > On 4/19/19 12:35 PM, Ken Tanzer wrote: > > > > > Thanks Adrian.  You are as usual correct.  (I had a bunch of tables > > created by a function that I assumed were serial, but were not.) > > Identity columns still seem tidier and more manageable.  Can you > tell if > > the function I referenced would change the ownership or not? > > I believe in 'when it doubt try it, whats the worst that can happen?:)': > > > I agree, and if I had a copy of 10+ running, I probably would have! :) > > I needed to be a superuser to run due to this: > ERROR:  permission denied for table pg_depend > CONTEXT:  SQL statement "UPDATE pg_depend >      SET deptype = 'i' >      WHERE (classid, objid, objsubid) = ('pg_class'::regclass, > seqid, 0) >        AND deptype = 'a'" > PL/pgSQL function upgrade_serial_to_identity(regclass,name) line 31 at > SQL statement > > > test=# create table serial_test(id serial, fld_1 text); > CREATE TABLE > test=# \dp serial_test >                                  Access privileges >   Schema |    Name     | Type  | Access privileges | Column > privileges | > Policies > --------+-------------+-------+-------------------+-------------------+---------- >   public | serial_test | table |                   | >    | > (1 row) > > test=# select upgrade_serial_to_identity('serial_test', 'id'); >   upgrade_serial_to_identity > ---------------------------- > > (1 row) > > test=# \d serial_test >                           Table "public.serial_test" >   Column |  Type   | Collation | Nullable |             Default > > --------+---------+-----------+----------+---------------------------------- >   id     | integer |           | not null | generated by default as > identity >   fld_1  | text    |           |          | > > > test=# \dp+ serial_test >                                  Access privileges >   Schema |    Name     | Type  | Access privileges | Column > privileges | > Policies > --------+-------------+-------+-------------------+-------------------+---------- >   public | serial_test | table |                   | >    | > (1 row) > > > Maybe I'm missing it, but I'm not really sure what that is supposed to > be telling me about the ownership of the sequence. > > The scenario I'm wondering about is: > > Table A owned by User 1, and has column created as serial > The created sequence is altered to be owned by User 2 (with User 1 > granted select & update) > upgrade_serial_to_identity applied to Table A > At that point, who owns the sequence? > > I can wait until I've got 10+ running and try it myself, but I thought > maybe someone would know the answer and be willing to share. select version(); version ---------------------------------------------------------------------------------------------------------------------------- PostgreSQL 11.2 on x86_64-pc-linux-gnu, compiled by gcc (SUSE Linux) 7.3.1 20180323 [gcc-7-branch revision 258812], 64-bit select session_user, current_user; session_user | current_user --------------+-------------- aklaver | aklaver create table serial_test(id serial, fld_1 text); CREATE TABLE \d List of relations Schema | Name | Type | Owner --------+--------------------+----------+---------- public | serial_test | table | aklaver public | serial_test_id_seq | sequence | aklaver test_(aklaver)> \c - postgres You are now connected to database "test" as user "postgres". test_(postgres)# select session_user, current_user; session_user | current_user --------------+-------------- postgres | postgres (1 row) test_(postgres)# select upgrade_serial_to_identity('serial_test', 'id'); upgrade_serial_to_identity ---------------------------- (1 row) List of relations Schema | Name | Type | Owner --------+--------------------+----------+---------- public | serial_test | table | aklaver public | serial_test_id_seq | sequence | aklaver The function is working directly on the system catalogs and I do not anything that changes ownership: UPDATE pg_depend SET deptype = 'i' WHERE (classid, objid, objsubid) = ('pg_class'::regclass, seqid, 0) AND deptype = 'a'; -- mark the column as identity column UPDATE pg_attribute SET attidentity = 'd' WHERE attrelid = tbl AND attname = col; > > Thanks! > > Ken > > > -- > AGENCY Software > A Free Software data system > By and for non-profits > /http://agency-software.org// > /https://demo.agency-software.org/client/ > ken.tanzer@agency-software.org > (253) 245-3801 > > Subscribe to the mailing list >  to > learn more about AGENCY or > follow the discussion. -- Adrian Klaver adrian.klaver@aklaver.com