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 1hjIXY-0007lx-0w for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 07:21:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hjIXW-0001Bm-Lj for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 07:21:50 +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 1hjIXW-0001Bf-79 for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2019 07:21:50 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjIXT-0003Ix-7q for pgsql-general@postgresql.org; Fri, 05 Jul 2019 07:21:49 +0000 Received: by mail-wm1-x341.google.com with SMTP id f17so8237707wme.2 for ; Fri, 05 Jul 2019 00:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=aI/O3pWuCJ9WgBmuiIv9e4wlHnOVdUz7tZBpIyblgPs=; b=kCoB6WKBsuvjb3e+6fylFU4LbfE2FxIpgGyPEwsJY5R6LKwtQwLGIi4MzoLhg5XZM1 1ZOI2z36Gp3SA2RZDTivfh3Fdo0slZczQS8o9KK+ix6eVFXa1d1Jl38JD62W4EJ6dbBl aA8XuDG1+Q594xQ4tvusviB3Plk3FU9RahdsYneLn/ja+Cz2Zx59mz8fPGYX+jfhTVtn 2GoL1Vb3FbpdTHulEbnZkSDJ/3LdXKHn5a7WIgWm4tmwKxI6wM+qJOuX0W1ksG78sqYq 4G6rGn9j7OY4T2d0AG3YnYaGKR1mraeGclIxs8aHrGZzI3EXhQIV02xWecKNkZBU1i2G qJTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=aI/O3pWuCJ9WgBmuiIv9e4wlHnOVdUz7tZBpIyblgPs=; b=f6Yo/PzofRt54UChFIL8+Ss4gutwfNn24NeOTmZtGHK8MTR88Dpnti2OEBCxUawNeU hU3u9prg46YXhJF9yl/2pybYrK+6XEJEwm0RA7tGfyaENjRLjysqDfxPsqjLFjaagyDZ 6uK594AzC951XZg+m2C395V1tyMjZcp9wXqBNO8ANTYcduD7bzuzh3HDnfT58o3xw4jr TImfvpWxTB1iTdCvdlgku5qSO4mCUwFWvqnkFR+iQViEdRp+B0sRCWu/P8RLxDFrMOv/ 9izPYThnGw6b5U1ADWDiBDnjTMB+aAYeIKsiaQ8A2BGcQ7zAgt4ydciV2VvEEU6qhvd3 1W+g== X-Gm-Message-State: APjAAAXO0NYJogEs+08i3yl14FO02y0yjS753EB3pq6tCpeKfnMhAy3f KLxzDG5Kg5MTC7BOHDjtR1vMbA== X-Google-Smtp-Source: APXvYqxI1L6jKqTDGNbLJcbLpg2MAseOsTAsP3XvtlbvMEvOIEWPYD2kJ6imcqJb/p0Um8Nn6HhrHA== X-Received: by 2002:a05:600c:284:: with SMTP id 4mr788612wmk.12.1562311305114; Fri, 05 Jul 2019 00:21:45 -0700 (PDT) Received: from localhost.localdomain (217-149-172-156.nat.highway.telekom.at. [217.149.172.156]) by smtp.gmail.com with ESMTPSA id u6sm4052129wrw.15.2019.07.05.00.21.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 05 Jul 2019 00:21:44 -0700 (PDT) Message-ID: <9dcaef4ca4f464078c22d4658eabd6baf43f9940.camel@cybertec.at> Subject: Re: Converting to identity columns with domains on PK columns From: Laurenz Albe To: PegoraroF10 , pgsql-general@postgresql.org Date: Fri, 05 Jul 2019 09:21:44 +0200 In-Reply-To: <1562269287792-0.post@n3.nabble.com> References: <1562269287792-0.post@n3.nabble.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PegoraroF10 wrote: > Domains on Postgres are really strange to me. Am I creating a domain which is > exactly equal to integer, right ? > > create domain i32 as integer; > create domain T50 as varchar(50); > > Create table MyTable( > ID I32 not null primary key, > Description T50); > > Then, after inserts and updates done to that table, I want to convert that > primary key to a identity column. > > alter table MyTable alter ID add generated always as identity; > > ERROR: identity column type must be smallint, integer, or bigint > > So, What do I need do to create this identity column ? > Why Postgres consider different I32 and integer ? A domain is more than just a different name for a data type, so the system doesn't treat them as identical. Another way to proceed would be: ALTER TABLE mytable ALTER id TYPE integer; ALTER TABLE mytable ALTER id ADD GENERATED ALWAYS AS IDENTITY; That would not rewrite the table, just "relabel" the type name to "integer" and then convert it to an identity column. Why do you want that extra level of obfuscation rather than calling an integer an integer? Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com