Re: [SQL] How to handle a requirement for nextval

Поиск
Список
Период
Сортировка
От The Web Administrator
Тема Re: [SQL] How to handle a requirement for nextval
Дата
Msg-id 3561879F.BE00E0B4@wizard.ca
обсуждение исходный текст
Ответ на Re: [SQL] How to handle a requirement for nextval  (Herouth Maoz <herouth@oumail.openu.ac.il>)
Список pgsql-sql
Ok, first of all you have given me the EXACT answer I was looking for. But
trust me, I poured over the docs, and there was no ref to a man page on
'create_sequence', otherwise I would have jumped all over it.. (I am using 6.2,
that might be the problem :>) Yes, I saw the OID thing, but that didn't seem
too standard SQL. The biggest problem I see in PostGres is the wide mixture of
docs. Maybe all the examples and readme's should be put together in a more
common package.  Possibly a doc package?

Herouth Maoz wrote:

> At 23:33 +0300 on 18/5/98, The Web Administrator wrote:
>
> > What I want is that the Primary Key (Only Key) be type_id, and int, and
> > the first item that I insert should have type_id as '1', next will be
> > '2'  etc..
> > I could have every insert into this table include a type_id, but that
> > seems unessary.
> > Can I have something like default='nextval' ?
>
> In order to create an auto-incrementing field - one which will
> automatically receive the value 1 for the first row inserted, 2 for the
> second, and so on - you have to define a sequence. For example:
>
> CREATE SEQUENCE emp_no;
>
> Then you define your table. Assuming you want an employee table in which
> the emp_id field is autoincrementing, here is what you write:
>
> CREATE TABLE emp
> (
>     emp_id    int4
>               DEFAULT nextval( 'emp_no' )
>               NOT NULL
>     -- Other fields here
> );
>
>




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

Предыдущее
От: "Jose' Soares Da Silva"
Дата:
Сообщение: Re: [SQL] How to handle a requirement for nextval
Следующее
От: "Anton Stöckl"
Дата:
Сообщение: Re: [SQL] Case in-sensitive searches