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

From Chris
Subject Re: nextval, sequences and sequencenames
Date
Msg-id 5.1.0.14.0.20010815120743.0327b010@cooee.cybersydney.com.au
Whole thread Raw
In response to Re: nextval, sequences and sequencenames  (missive@frontiernet.net (Lee Harr))
Responses Re: Re: nextval, sequences and sequencenames  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Hi,

> > My question:
> > is there anyway of retreiving the sequence_name corresponding to the
> > respective column,
> > knowing just the tablename and columnname?
> >
> > The reason I need to do this, is because the application I write
> > dynamicly creates new tables, and I have no way of knowing the sequence
> > name before hand.
> >
>
>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

so if we use the serial datatype to create a column called "xyz" in the
table "abc" the sequence name is :

abc_xyz_seq

Make sense?


-----------------
      Chris Smith
http://www.squiz.net/

pgsql-general by date:

Previous
From: missive@frontiernet.net (Lee Harr)
Date:
Subject: Re: nextval, sequences and sequencenames
Next
From: Barry Lind
Date:
Subject: Re: [ADMIN] initdb on postgresql 7.1.2 running under cygwin on win 2000