Re: Re: nextval, sequences and sequencenames

Поиск
Список
Период
Сортировка
От Wieger Uffink
Тема Re: Re: nextval, sequences and sequencenames
Дата
Msg-id 3B7A37A2.E8A45522@usmedia.nl
обсуждение исходный текст
Ответ на nextval, sequences and sequencenames  (Wieger Uffink <wieger@usmedia.nl>)
Ответы Re: Re: nextval, sequences and sequencenames  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
Hi,

First of all thanks for the reactions, but I think I have probably not
made my problem clear enough.

I know the sequence name will be some combination, usually as
'tablename_columnname_seq',
when implicitly created during table creation.
But when I create my table 'maincompetencies' with serial column
'maincompetencid'
the sequence is named 'maincompetenc_maincompetenc_seq'. Clearly not the
same as the above mentioned naming formula.

I have a hunch that table and column names are cut off after the first
13 characters, but im not sure if this is true, or will maybe change in
future versions of postgre.

What I would really like to do is just query Postgre, give the tablename
and columnname in question, and retreive the exact sequencename. I know
Postgre 'knows' this, it has that info stored somewhere, it just wont
tell me :)

thanks,

Wieger


Chris wrote:
>
> 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/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--
Wieger Uffink
tel: +31 20 428 6868
fax: +31 20 470 6905
web: http://www.usmedia.nl

В списке pgsql-general по дате отправления:

Предыдущее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Re: nextval, sequences and sequencenames
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Re: nextval, sequences and sequencenames