From: Laurenz Albe <laurenz.albe@cybertec.at>
To: PegoraroF10 <marcos@f10.com.br>
To: pgsql-general@postgresql.org
Subject: Re: Converting to identity columns with domains on PK columns
Date: Fri, 05 Jul 2019 09:21:44 +0200
Message-ID: <9dcaef4ca4f464078c22d4658eabd6baf43f9940.camel@cybertec.at> (raw)
In-Reply-To: <1562269287792-0.post@n3.nabble.com>
References: <1562269287792-0.post@n3.nabble.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: laurenz.albe@cybertec.at, marcos@f10.com.br
Subject: Re: Converting to identity columns with domains on PK columns
In-Reply-To: <9dcaef4ca4f464078c22d4658eabd6baf43f9940.camel@cybertec.at>
References: <1562269287792-0.post@n3.nabble.com> <9dcaef4ca4f464078c22d4658eabd6baf43f9940.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox