Re: CREATE TABLE LIKE and SERIAL - Mailing list pgsql-general

From Mark Morgan Lloyd
Subject Re: CREATE TABLE LIKE and SERIAL
Date
Msg-id hcfp1j$e7v$1@pye-srv-01.telemetry.co.uk
Whole thread Raw
In response to CREATE TABLE LIKE and SERIAL  (Mark Morgan Lloyd <markMLl.pgsql-general@telemetry.co.uk>)
List 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 by date:

Previous
From: Thom Brown
Date:
Subject: Re: CREATE TABLE LIKE and SERIAL
Next
From: db de
Date:
Subject: pg_start_backup question