Re: serial not accepted as datatype in ALTER TABLE ... ALTER COLUMN

From: Andy Fan <zhihuifan1213(at)163(dot)com>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: serial not accepted as datatype in ALTER TABLE ... ALTER COLUMN
Date: 2024-02-20 01:17:37
Message-ID: 87bk8cgc4w.fsf@163.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> writes:

> On Sun, Feb 18, 2024 at 1:59 PM Andy Fan <zhihuifan1213(at)163(dot)com> wrote:
>>
>>
>> I tried your idea with the attatchment, it is still in a drafted state
>> but it can be used as a prove-of-concept and for better following
>> communicating. Just one point needs to metion is serial implies
>> "default value" + "not null" constaint. So when we modify a column into
>> serial, we need to modify the 'NULL value' and only to the default value
>> at the RewriteTable stage.
>>
>
> I am surprised that this requires changes in ReWrite. I thought adding
> NOT NULL constraint and default value commands would be done by
> transformColumnDefinition(). But I haven't looked at the patch close
> enough.

Hmm, I think this depends on how to handle the NULL values before the
RewriteTable.

Consider the example like this:

\pset null (null)
create table t(a int);
insert into t select 1;
insert into t select;

postgres=# select * from t;
a
--------
1
(null)
(2 rows)

since serial type implies "not null" + "default value", shall we raise error
or fill the value with the "default" value? The patch choose the later
way which needs changes in RewirteTable stage, but now I think the raise
error directly is an option as well.

--
Best Regards
Andy Fan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Euler Taveira 2024-02-20 01:28:17 Re: speed up a logical replica setup
Previous Message Jelte Fennema-Nio 2024-02-20 00:21:56 Re: Have pg_basebackup write "dbname" in "primary_conninfo"?