| From: | ron <ron(at)sattargroup(dot)com> | 
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org | 
| Subject: | nexval error duplicate key | 
| Date: | 2002-02-14 19:55:28 | 
| Message-ID: | a05100309b891c1fa5fd5@[10.0.1.5] | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-sql | 
I am getting the darnest error here
I think I narrowed it down
Problem:
In a simplified version of the program is the following, this is 
completed in ColdFusion which I don't think is an issue
My understanding of SQL database is limited
I set up a table
field
	id
	name_insert
I basically want to add a name in the 'name_insert' field and let 
'id' to incrementally increase automatically
An html  was created with ONLY one field to add a name
An html was created to list the names and modify the name
I used the code something like the following:
CREATE TABLE name_table (
         id   SERIAL,
         name_insert TEXT
     );
Basically when the name is inserted it works fine
I check the table I get the following
for example DATA 1
	1 john
	2 mary
	3 josephine
	4 ron
Then here is the issue
	I modify 2 mary to 2 jane
	the database modified to
DATA 2
	1 john
	3 josephine
	4 ron
	2 jane
When I use postgresql admin I get DATA 2
the number is OUT of order
NOW when I add a new value
it give me an error that states:
--------------------------------------------------------
Error Occurred While Processing Request
Error Diagnostic Information
ODBC Error Code = 08S01 (Communication link failure)
Error while executing the query; ERROR: Cannot insert a duplicate key 
into unique index name_pkey
The error occurred while processing an element with a general 
identifier of (CFQUERY), occupying document position (1:61) to 
(1:110).
--------------------------------------------------------
I only put the relavent error above
It seems when the nextval is used here the sql thinks the last value 
is '3' because the last value is '2 jane' so it seems logical to get 
'3' as the next value.
Additional information:
If I move the highest value '4 ron'  by editing it, just as I edited 
'2 jane' then I get '4 ronald'
DATA 3
	1 john
	3 josephine
	2 jane
	4 ronald
Now when I add a new record like 'sam' no error
DATA 3
	1 john
	3 josephine
	2 jane
	4 ronald
	5 sam
so now it works
What's the deal?
doesn't 'nexval' find the greatest value? or does it seem to get the 
last value in the list
so I am thinking the best way is to sort the table OR I am thinking 
that when I find the next value it does a sort then find the last 
value
so I am stuck any ideas of what I can do?
Ron Sattar
--
		Sattar Group, Inc.	ICQ 153 46 249
		Voice 773 725 3445	Fax 773 442 0064
			http://www.SattarGroup.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Hunter, Ray | 2002-02-14 21:02:26 | Front and Back End | 
| Previous Message | Oleg Bartunov | 2002-02-14 19:37:29 | Re: Is this the most efficent way to child nodes off a N-ary |