Thread: Can't add records

Can't add records

From
Setyo Nugroho
Date:
Hi all,

Wrote a small program using Qt. After some tests with another database,
usingthe very same program, I found something erroneous in my program.
- editing & deleting records: OK
- adding records: NO
I got this eror message:

"QPSQL:unable to create query.
Error: cannot insert a duplicate key into unique index route_pkey."

I am (almost) quite sure, this problem lies in the database. A double
check using a hand-coded program and a gui-based prog (Qt designer) has
been made, those produce same error.
This is my database:

cstowdb=# \d route;
            Table "route"
  Column  |     Type      | Modifiers
----------+---------------+-----------
 route_id | integer       | not null
 port1    | integer       |
 port2    | integer       |
 port3    | integer       |
 port4    | integer       |
 port5    | integer       |
 voynr    | character(10) |
Indexes: route_routeid_idx
Primary key: route_pkey

What does the above-mentioned error message mean?
How to fix the problem?

Regards,
Setyo Nugroho



Re: Can't add records

From
Josh Berkus
Date:
Setyo,

> "QPSQL:unable to create query.
> Error: cannot insert a duplicate key into unique index route_pkey."

> What does the above-mentioned error message mean?
> How to fix the problem?

It means that you are trying to insert a dumplicate RouteID into the table,
which is rejected because it's a violation of your primary key (RouteID).

I can think of several reasons why this would happen.   How is your interface
getting new values for the RouteID column?

--
-Josh Berkus
 Aglio Database Solutions
 San Francisco


Re: Can't add records

From
Chris Smith
Date:
Hi,

>Hi all,
>
>Wrote a small program using Qt. After some tests with another database,
>usingthe very same program, I found something erroneous in my program.
>- editing & deleting records: OK
>- adding records: NO
>I got this eror message:
>
>"QPSQL:unable to create query.
>Error: cannot insert a duplicate key into unique index route_pkey."

Your script is trying to insert a value that is already there.

In your table you have values 1,2,3,4,5.

Your script is trying to insert one of these values in again and giving the
error.

Chris Smith


 >> 92 Jarrett St Leichhardt, Sydney, NSW 2040 ...>
T: + 61 2 9568 6866
F: + 61 2 9568 6733
W: http://www.squiz.net/
.....>> Open Source - Own it - Squiz.net ...../>


Re: Can't add records

From
"von Schwerdtner, Thomas (GXS, FPI)"
Date:

>
> Wrote a small program using Qt. After some tests with another
> database,
> usingthe very same program, I found something erroneous in my
> program.
> - editing & deleting records: OK
> - adding records: NO
> I got this eror message:
>
> "QPSQL:unable to create query.
> Error: cannot insert a duplicate key into unique index route_pkey."
<snip/>

This usually means that your insert command is attempting to duplicate a value in a sequence, which for your table looks to be the route_id column.

-Tom