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

Поиск
Список
Период
Сортировка
От Andy Fan
Тема Re: serial not accepted as datatype in ALTER TABLE ... ALTER COLUMN
Дата
Msg-id 87bk8cgc4w.fsf@163.com
обсуждение исходный текст
Ответ на Re: serial not accepted as datatype in ALTER TABLE ... ALTER COLUMN  (Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>)
Список pgsql-hackers
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> writes:

> On Sun, Feb 18, 2024 at 1:59 PM Andy Fan <zhihuifan1213@163.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




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Jelte Fennema-Nio
Дата:
Сообщение: Re: Have pg_basebackup write "dbname" in "primary_conninfo"?
Следующее
От: "Euler Taveira"
Дата:
Сообщение: Re: speed up a logical replica setup