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 1hHbGx-00047k-Tx for pgsql-general@arkaria.postgresql.org; Fri, 19 Apr 2019 21:42:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hHbGw-0004md-Fk for pgsql-general@arkaria.postgresql.org; Fri, 19 Apr 2019 21:42:14 +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 1hHbGu-0004mV-Ee for pgsql-general@lists.postgresql.org; Fri, 19 Apr 2019 21:42:14 +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 1hHbGl-0007TT-FG for pgsql-general@lists.postgresql.org; Fri, 19 Apr 2019 21:42:11 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 86092793; Fri, 19 Apr 2019 17:42:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 19 Apr 2019 17:42:00 -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=x ucCfywp788uD3u6hwU5p/Hgzx2lcdMmMCvE2sSjEmc=; b=J76PQPDEQX8F0J6gs kXjt0kux3wclzPgldmAoyl0g13LB2gi7PsNiLsr5CNGeDudL3twasQ7GXzxhILeG 4/OKRu1v2SBBMPcJjr9DfZBcntWh82/yweJU8pS/oxO295GPP6twtgXXZNiDN+l4 PjRErFOhUzJ1bDLHh+xH7F39pFrsRfLOScpgoFH0EmbSqp6/FuYRmmbzfDzyuJoO U0/sDf6T1bGIDnMUu1cwB5IYiNjrXbGJ+xqajrlyC8qakl/XEqoD4Cq0fLeLVZas UZJ/0fWudYZTKRsx5TrNhUH66juQA214CND/+IMKCZj0DC2VE54W3V0oSwjnsenE adRSA== 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=xucCfywp788uD3u6hwU5p/Hgzx2lcdMmMCvE2sSjE mc=; b=nbF9FwBL10+KcoLECVo6hjFyXnCp5dMExxNv1ZAWG9qOuXBoLiGK+Gg0i n3aotA+gt/yfqd8xHJHnG4gZ9CnKH2xQRWYdcfZzqL0fGprsdkVuJnC2SrBOv50S kDaDL+Pb31qRnatoQdouXDci2K3GKQEjFZR4rxULpM5TJcUBq5Yvpi4ff+zNQR4b S5L28/i2DqLH9UdKtqxj0WhpPPO0IglUiY/qIqBkyWxXBvkT9mlNWfPc4pCcG6RD 9E2OxTS0rO0z5Z98O0/KTKTP66/8eVTIA37FRiI63UACBJTsetPmqrzCmE32YNtR UrX62AFjoIcd249/hkFn9cZ3mCGcw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrfeelgddtudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghdpshgvrhhirghlrdhiugdp rghgvghntgihqdhsohhfthifrghrvgdrohhrghenucfkphephedtrdduleejrdektddrvd enucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgr vhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt 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 40450E4122; Fri, 19 Apr 2019 17:41:59 -0400 (EDT) Subject: Re: Primary key data type: integer vs identity To: Ken Tanzer Cc: "pgsql-generallists.postgresql.org" References: <4d387c8e-a261-0734-a10f-dfde7ce538f0@aklaver.com> <2752f2d1-2cec-1df4-21f7-b0b004f8e500@aklaver.com> <47f1fa10-fb71-0f58-9dcf-c5083680059a@aklaver.com> From: Adrian Klaver Message-ID: Date: Fri, 19 Apr 2019 14:41:57 -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 2:31 PM, Ken Tanzer wrote: > On Fri, Apr 19, 2019 at 1:39 PM Adrian Klaver > Thanks, though I don't see what this shows, since there were not > separate users involved.  So I loaded up a copy of 11.2, and discovered Well the table was created by one user and the serial was changed to IDENTITY by another. > that you actually can't change the ownership of a sequence created by > serial. > > ag_tz_test=# ALTER SEQUENCE t_serial_id_seq OWNER TO develop; > ERROR:  cannot change owner of sequence "t_serial_id_seq" > DETAIL:  Sequence "t_serial_id_seq" is linked to table "t_serial". That is covered here: https://www.postgresql.org/docs/11/sql-altersequence.html "OWNED BY table_name.column_name ... The specified table must have the same owner and be in the same schema as the sequence. ..." Which to me means the opposite is true also. Though you can: " Specifying OWNED BY NONE removes any existing association, making the sequence “free-standing”. " > > I also missed the part in the article where it talks about assigning > ownership to the column.  In psql, it's easy to miss because a \ds (or > \ds+) (as opposed to a \d) shows the user that owns the sequence, not a > column: > > > test=# \ds+ >                             List of relations >  Schema |       Name        |   Type   | Owner |    Size    | Description > --------+-------------------+----------+-------+------------+------------- >  public | t_serial_id_seq   | sequence | u1    | 8192 bytes | > > Whereas if you look at \d it shows the column: > > > test=# \d+ t_serial_id_seq >                   Sequence "public.t_serial_id_seq" >   Type   | Start | Minimum |  Maximum   | Increment | Cycles? | Cache > ---------+-------+---------+------------+-----------+---------+------- >  integer |     1 |       1 | 2147483647 |         1 | no      |     1 > Owned by: public.t_serial.id > > (Side note: it is surprising that the Size and Description don't show up > with \d+.  I always thought that a \d+ was the best way to get all the > detail on an object.) > > But even if you drop the default on the column, it doesn't seem like you > can change the sequence's owner: > > test=# ALTER TABLE t_serial ALTER COLUMN id DROP DEFAULT; > ALTER TABLE > test=# alter sequence t_serial_id_seq OWNER TO u2; > ERROR:  cannot change owner of sequence "t_serial_id_seq" > DETAIL:  Sequence "t_serial_id_seq" is linked to table "t_serial". > > Although you can drop it: > > DROP SEQUENCE t_serial_id_seq; > DROP SEQUENCE > > Anyhoo, I've learned a bit more today, and thanks for your help! > > Cheers, > 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