sequence id

Поиск
Список
Период
Сортировка
От stefan@extum.com
Тема sequence id
Дата
Msg-id Pine.LNX.4.44.0207171259170.29052-100000@extum.com
обсуждение исходный текст
Ответы Re: sequence id  (nconway@klamath.dyndns.org (Neil Conway))
Список pgsql-general
Hello all,

I am learning PostgreSQL and I found it really interesting. I am writing
some sql scripts to create some
tables and then add data via INSERT.

A question about SERIAL Data type. If I have a table definition like:



CREATE TABLE www_server (
        id serial NOT NULL,
        role char(5),
        webserver varchar(25),
        ip varchar(12),
        hardware varchar(80),
        software varchar(80),
        checked DATE
         );

And have an INSERT statement like:

INSERT INTO www_server
    (role,webserver,ip,hardware,software,checked) VALUES
        (
        'www',
        'webserver1',
        '',
        'Pentium II, 256 MBRAM',
        'RedHat 7.3',
        '2002-07-16'
        );


my id which is a SERIAL will be incremented ok. But lets say I make
mistakes and want to delete from www_server everything. The next id
available will be which one was left previously. So If I run the INSERT
once I get 1 for my 'id'. If I delete and re-run my INSERT my 'id' is 2.

Do I need to do a VACUUM or how to restart from 1 ? I tried VACUUM; but
nothing worked. What worked was to DROP SEQUENCE and then the TABLE.

On the other hand is somehow reservated under PostgreSQL the name 'ID' for
column ?
If I create a table with ID works fine but selects are not working. If I
have 'id' for the column I can do SELECTs.

thanks
stefan




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

Предыдущее
От: Curt Sampson
Дата:
Сообщение: Re: Pushing PostgreSQL to the Limit (urgent!)
Следующее
От: mixo
Дата:
Сообщение: age