Re: Re: nextval, sequences and sequencenames

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Chris <csmith(at)squiz(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: nextval, sequences and sequencenames
Date: 2001-08-15 08:04:43
Message-ID: 20010815180443.A9969@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice

On Wed, Aug 15, 2001 at 12:14:02PM +1000, Chris wrote:
> >If it is very difficult finding that sequence name (I'm not sure)
> >You may want to create the sequence yourself instead of using SERIAL.
> >Then you would know the name.
>
> Not hard at all.
>
> csmith=# create table test (testid serial, name text);
> NOTICE: CREATE TABLE will create implicit sequence 'test_testid_seq' for
> SERIAL column 'test.testid'
> NOTICE: CREATE TABLE/UNIQUE will create implicit index 'test_testid_key'
> for table 'test'
> CREATE
>
> Sequence name becomes <tablename>_<columnname>_seq

Actually, it's a bit more complicated than that. Since the maximum
identifier length is 32 or so, if the above identifier comes out too long,
various rules are applied to make it shorter.

If you want a guarenteed name, I suggest not using serial and building the
sequence yourself. Then you can use any naming convention you like.

--
Martijn van Oosterhout <kleptog(at)svana(dot)org>
http://svana.org/kleptog/
> It would be nice if someone came up with a certification system that
> actually separated those who can barely regurgitate what they crammed over
> the last few weeks from those who command secret ninja networking powers.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gordan Bobic 2001-08-15 08:14:02 Re: nextval, sequences and sequencenames
Previous Message Cedar Cox 2001-08-15 06:37:26 Re: Re: Bug#108286: case sensitivity in column names

Browse pgsql-novice by date

  From Date Subject
Next Message Gordan Bobic 2001-08-15 08:14:02 Re: nextval, sequences and sequencenames
Previous Message Chris 2001-08-15 02:14:02 Re: nextval, sequences and sequencenames