Re: Need help to implement Primary Key.

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: Need help to implement Primary Key.
Дата
Msg-id aab0c4e7-4c05-4245-9956-c1584aadf132@gmx.net
обсуждение исходный текст
Ответ на Need help to implement Primary Key.  (Gambhir Singh <gambhir.singh05@gmail.com>)
Ответы Re: Need help to implement Primary Key.
Список pgsql-admin
Gambhir Singh schrieb am 08.02.2024 um 11:30:

> I have a table with a record count of ~500 million (496,098,390).
> There is no primary key in this table. Now I need to set up a primary
> key on this table. I can't find a way to set up a primary key. I
> tried to add a new column with IDENTITY but it is not allowing null
> value for existing rows and I don't know how to update the unique
> value for existing records.

If you add an identity column, it will automatically be populated


alter table foo
   add id bigint generated always as identity not null;

Once that has finished (which will take some time given the size of the table),
you can add the primary key:

alter table foo
   add constraint pk_foo primary key (id);





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

Предыдущее
От: Gambhir Singh
Дата:
Сообщение: Need help to implement Primary Key.
Следующее
От: Holger Jakobs
Дата:
Сообщение: Re: Need help to implement Primary Key.