Re: Converting to identity columns with domains on PK columns - Mailing list pgsql-general

From Laurenz Albe
Subject Re: Converting to identity columns with domains on PK columns
Date
Msg-id 9dcaef4ca4f464078c22d4658eabd6baf43f9940.camel@cybertec.at
Whole thread Raw
In response to Converting to identity columns with domains on PK columns  (PegoraroF10 <marcos@f10.com.br>)
Responses Re: Converting to identity columns with domains on PK columns
List pgsql-general
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




pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Why does jsonb_set() remove non-mentioned keys?
Next
From: Gianni Ceccarelli
Date:
Subject: Re: Why does jsonb_set() remove non-mentioned keys?