Re: CREATE TABLE LIKE and SERIAL

Поиск
Список
Период
Сортировка
От Mark Morgan Lloyd
Тема Re: CREATE TABLE LIKE and SERIAL
Дата
Msg-id hcfp1j$e7v$1@pye-srv-01.telemetry.co.uk
обсуждение исходный текст
Ответ на CREATE TABLE LIKE and SERIAL  (Mark Morgan Lloyd <markMLl.pgsql-general@telemetry.co.uk>)
Список pgsql-general
Tom Lane wrote:

> Thinking of SERIAL as a type is your first mistake ;-).  It is not a
> type.  It is a shorthand for making a sequence and sticking a suitable
> default on a plain integer column.  So what LIKE sees is an integer
> column with a default, and it copies that.

That's entirely fair, and the manual section dealing with types is very
careful to start off with "The data types serial and bigserial are not
true types".

However I think that the description of CREATE TABLE ... LIKE really
could do with a "health warning" for this case.

Looking at this very slightly deeper and assuming that the user is aware
of the pitfalls, it's obviously easy for him to create a new sequence
and to use it as the default value. But what if he wants the new
sequence to inherit the current state of an existing one: might I
suggest CREATE SEQUENCE ... LIKE would be appropriate here?

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

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

Предыдущее
От: Thom Brown
Дата:
Сообщение: Re: CREATE TABLE LIKE and SERIAL
Следующее
От: db de
Дата:
Сообщение: pg_start_backup question