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

From: Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar>
To: "Duffey, Kevin" <KDuffey(at)marketron(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why do I need to pass value for Serial type in Insert/Update?
Date: 2003-09-12 16:45:20
Message-ID: 200309121345.20723.martin@bugs.unl.edu.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)unl(dot)edu(dot)ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Josh Berkus 2003-09-12 16:49:52 Re: best arrangement of 3 disks for (insert) performance
Previous Message Tom Lane 2003-09-12 16:40:10 Re: postmaster segfault with tsearch2?