Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: CREATE TABLE LIKE and SERIAL


  • From: Thom Brown <thombrown(at)gmail(dot)com>
  • To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • Cc: Mark Morgan Lloyd <markMLl(dot)pgsql-general(at)telemetry(dot)co(dot)uk>, pgsql-general(at)postgresql(dot)org
  • Subject: Re: CREATE TABLE LIKE and SERIAL
  • Date: Fri, 30 Oct 2009 21:37:05 +0000
  • Message-id: <bddc86150910301437j7e008436v2b2b001249200aae@mail.gmail.com> <text/plain>

2009/10/30 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Thom Brown <thombrown(at)gmail(dot)com> writes:
>> I can see why you wouldn't expect it to end up sharing the same
>> sequence.  If you were to manually create a sequence and wanted to use
>> it on a column, you probably wouldn't bother using the SERIAL
>> datatype, but use integer instead.  So really since we know the first
>> table has a datatype of SERIAL on one of its columns, we might instead
>> wish to have it create a new implicit sequence instead of merely
>> converting it to an INTEGER datatype and adding a default constraint
>> to the same sequence as the original table.
>
> 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.
>

Well I realise SERIAL is a convenience rather than a datatype in its
own right, but I'm surprised that LIKE can't differentiate between a
column created with integer and one created with serial.  The table
continues to report a serial datatype after its creation.  Is it's
reference too low-level?  Could it be altered to support recognition
of serial usage?

Thom



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group