PostgreSQL insert/Update problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Love_Daddy
Forum Commoner
Posts: 61
Joined: Wed Jul 10, 2002 6:55 am
Location: South Africa
Contact:

PostgreSQL insert/Update problem

Post by Love_Daddy »

Hi All,

Thank for your help so far.
I have another problem, everytime I try to insert or update my table, I get the following error:
ERROR: pg_atoi: error in "Romeo": can't parse "Romeo"

With the following insert

INSERT INTO emp VALUES('Romeo',2584) ;

Table: emp
Values: Id, name,salary

Please help..

Thanks
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

Try

Code: Select all

INSERT INTO emp (name, salary) VALUES ('Romeo', 1234)
If you don't tell pgsql what fields your sending it assumes it is all fields in the right order. With my query I tell that I want to set the ID field to DEFAULT (mybee a serial field -> next number?).
User avatar
Love_Daddy
Forum Commoner
Posts: 61
Joined: Wed Jul 10, 2002 6:55 am
Location: South Africa
Contact:

Re:PostgreSQL insert/Update

Post by Love_Daddy »

When I do has you say, I get another error message namely:
Cannot insert a duplicate key into unique index emp_id_key
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

I'm not sure, but it look's like your sequnce is broken. One way to fix this is (if you have a serial field):

Code: Select all

DROP SEQUENCE emp_Id_seq;
CREATE SEQUENCE emp_Id_seq START XX;
The emp_Id_seq works as: table_field_seq. Change XX to the next number you Id should be (SELECT MAX(Id)+1 FROM emp).

I cannot guarantee this will work. But it might be worth trying! (== Backup first!) :wink:
Post Reply