By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,917 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,917 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Thanks.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003

************************************************** *************************
"The information contained in this e-mail message may be confidential and
protected from disclosure. If you are not the intended recipient, any
dissemination, distribution or copying is strictly prohibited. If you think
that you have received this e-mail message in error, please e-mail the
sender at ex******@marketron.com."
************************************************** *************************

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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 | mm******@unl.edu.ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #2

P: n/a
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 | mm******@unl.edu.ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #3

P: n/a
On Fri, 12 Sep 2003, Duffey, Kevin wrote:
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 can do this in a few ways.

create table test (id serial unique, info text, num int);
insert into test (info,num) values ('abc',123);
insert into test (id, info, num) values (DEFAULT,'abc',123);
insert into test values (DEFAULT,'abc',123);
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #4

P: n/a
On Fri, 12 Sep 2003, Duffey, Kevin wrote:
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 can do this in a few ways.

create table test (id serial unique, info text, num int);
insert into test (info,num) values ('abc',123);
insert into test (id, info, num) values (DEFAULT,'abc',123);
insert into test values (DEFAULT,'abc',123);
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.