Re: CREATE TABLE LIKE and SERIAL

From: Mark Morgan Lloyd <markMLl(dot)pgsql-general(at)telemetry(dot)co(dot)uk>
To: pgsql-general(at)PostgreSQL(dot)org
Subject: Re: CREATE TABLE LIKE and SERIAL
Date: 2009-10-30 22:23:46
Message-ID: hcfp1j$e7v$1@pye-srv-01.telemetry.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-hackers 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]

In response to

Browse pgadmin-hackers by date

  From Date Subject
Next Message Tom Lane 2009-10-30 22:48:45 Re: CREATE TABLE LIKE and SERIAL
Previous Message Thom Brown 2009-10-30 21:58:20 Re: CREATE TABLE LIKE and SERIAL

Browse pgsql-general by date

  From Date Subject
Next Message Justin Pasher 2009-10-30 22:35:24 Re: Problem with plpython
Previous Message Thom Brown 2009-10-30 21:58:20 Re: CREATE TABLE LIKE and SERIAL