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 1hj8M9-00074n-9a for pgsql-general@arkaria.postgresql.org; Thu, 04 Jul 2019 20:29:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hj8L9-0005Tj-9V for pgsql-general@arkaria.postgresql.org; Thu, 04 Jul 2019 20:28:23 +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 1hj8L8-0005Tc-SR for pgsql-general@lists.postgresql.org; Thu, 04 Jul 2019 20:28:23 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj8L0-0004uY-JO for pgsql-general@postgresql.org; Thu, 04 Jul 2019 20:28:21 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id ECFAA21AF1; Thu, 4 Jul 2019 16:27:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 04 Jul 2019 16:27:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=W IRumIWHMHizHyD0K/zPNiwRqVU9rmKRBmkET5t5iz0=; b=RwBM+p/Leca26l5xz rKV83iyLdwu7+jKRVLqJbMRHGVtt+KKYR2WjDQp/Fsmat/SQPJK2fMvkwQPdj/o3 Xq+M3VJwrO7I2C14Mp7S94yEzotrl9tgcmNZTjNSJDKopp/5k7eX0b15WxSihxfD 9gPr+ZXZn3r5MJfxXvA65WABRsshFBYkAknoIqfyaSIoONYyU7rCcRjwiJ9R3C/F wmokgKH4r3fKLRDbjF736MUC78fuXg390WpBgGe3bmsSi8Wo+pL11T1AcLv6RK15 34SFBjPeplp+P9y7rh/O0CsoYV/nr8Rw61umkock7Vs4DEtplOExXjgvLMKmX9D9 uOH7g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm3; bh=WIRumIWHMHizHyD0K/zPNiwRqVU9rmKRBmkET5t5i z0=; b=CLfhoRzGSLZ5iz2Z4F6ONS9g5fXcwDRCAepmn8ath9s2Fqmcr5CxKWNC4 rzHVUt+yp04iiSZijof7pUxsikKoCeqNdxfqSJiUavM7ocqaCASgQNYJmhbnBw6W 4N7aNp1/kYy7WaTp4HqS6+DYyyh7cDO6Usw3P6he1a2I4VGPmXxHfgAEmUxz/9YI Jogi85cVK7vmHkF117azV0h6mINdD9SZT/zZMSiEOWA02I4pV6pxXOt41pZHcaPL aeDsDqYPqG9w2V8vgt9jE7tHX6RqdJLwRkhFJ8mTtyC6s1+9bm2jOtWRKwA/fxWL aHrZ7L23Heqp81YPb4VD6wTEOf5Ig== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrfedvgdduhedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdqrghrtghhihhvvgdrohhrghenucfkphepjedurddvuddvrdduhedtrddvtddvnecu rfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvg hrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id ED92A80063; Thu, 4 Jul 2019 16:27:53 -0400 (EDT) Subject: Re: Converting to identity columns with domains on PK columns To: PegoraroF10 , pgsql-general@postgresql.org References: <1562269287792-0.post@n3.nabble.com> <2a86ab61-0bdb-9ac9-22a0-02d3402ec7bd@aklaver.com> <1562270630672-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: Date: Thu, 4 Jul 2019 13:27:53 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <1562270630672-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 7/4/19 1:03 PM, PegoraroF10 wrote: > ok, thanks for the explanation but ... I cannot add a field and move data, > constraints, triggers, identity to it because my pk field will be > repositioned to the last field on that table and I have lots of other codes > which point to pk as the first field on every table. I stay away from using the index position of field for this reason. > > So, there is a way to convert that field to a identity field ? See my second option in previous post. Or, old school identity column:): create sequence id_seq owned by mytable.id; alter table mytable alter column id set default nextval('id_seq'); \d mytable Table "public.mytable" Column | Type | Collation | Nullable | Default -------------+------+-----------+----------+----------------------------- id | i32 | | not null | nextval('id_seq'::regclass) description | t50 | | | Indexes: "mytable_pkey" PRIMARY KEY, btree (id) > > > > > -- > Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > > > -- Adrian Klaver adrian.klaver@aklaver.com