Re: Re: nextval, sequences and sequencenames - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Re: nextval, sequences and sequencenames
Date
Msg-id 20010815180443.A9969@svana.org
Whole thread Raw
In response to Re: nextval, sequences and sequencenames  (Chris <csmith@squiz.net>)
List pgsql-general
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@svana.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.

pgsql-general by date:

Previous
From: "Alexander Fordyce"
Date:
Subject: OpenBSD 2.9 - installation works fine but psql won't run
Next
From: Wieger Uffink
Date:
Subject: Re: Re: nextval, sequences and sequencenames