Re: Why do I need to pass value for Serial type in Insert/Update?

Поиск
Список
Период
Сортировка
От Martin Marques
Тема Re: Why do I need to pass value for Serial type in Insert/Update?
Дата
Msg-id 200309121345.20723.martin@bugs.unl.edu.ar
обсуждение исходный текст
Ответ на Why do I need to pass value for Serial type in Insert/Update?  ("Duffey, Kevin" <KDuffey@marketron.com>)
Список pgsql-general
El Vie 12 Sep 2003 16:22, Duffey, Kevin escribió:
> I don't know if jdbc/java code requires this, but when I use two gui admin
> tools I found, and I insert a row into the table using their row editor
> feature, both require me to enter a number for the Serial type. I thought
> this type was used to auto-increment an id field and that I would not need
> to enter anything into it? Basically we need the normal indexed ID field
> for each table, and we want it to auto-increment. The serial shows a
> function of nextVal() or something like that, so I assume it
> auto-increments, and it shows unique and not-null. Can someone explain how
> serial is used, why would I still need to pass a value for it?

You have to take it off the insert list of columns.

id serial
name varchar(30)

You would do:

INSERT INTO table (name) VALUES ('Martín')

and the id value would be taken as the dafault, which is the next value of the
sequence.

--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués                  |        mmarques@unl.edu.ar
Programador, Administrador, DBA |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------


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

Предыдущее
От: Holger Marzen
Дата:
Сообщение: Re: query-question
Следующее
От: Ron Johnson
Дата:
Сообщение: Re: State of Beta 2