Re: Why do I need to pass value for Serial type in Insert/Update? - Mailing list pgsql-general

From Martin Marques
Subject Re: Why do I need to pass value for Serial type in Insert/Update?
Date
Msg-id 200309121345.20723.martin@bugs.unl.edu.ar
Whole thread Raw
In response to Why do I need to pass value for Serial type in Insert/Update?  ("Duffey, Kevin" <KDuffey@marketron.com>)
List 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 by date:

Previous
From: Holger Marzen
Date:
Subject: Re: query-question
Next
From: Ron Johnson
Date:
Subject: Re: State of Beta 2