HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlMinor

unable to insert row at id, but row does not exist

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
insertbutunableexistdoesrownot

Problem

Here is the weird problem i am facing. I am trying to enter data using following query

insert into product_product 
(id, product_tmpl_id, make_equip, model_equip, name_template, serial_num_equip, location_equip, issue_date_equip, issue_to_equip, remarks_equip, pr, ch,  categ_id,valuation) 
values (700,700,'Nikon','Action 10x50 Lookout','Nikon Action 10x50 Lookout','671386','40 Wall St.','5/13/2004 12:00:00 AM','','OM''s OFFICE',62,72,502,'manual periodic');


I get the error :

ERROR:  duplicate key value violates unique constraint "product_product_pkey"
DETAIL:  Key (id)=(700) already exists.

********** Error **********

ERROR: duplicate key value violates unique constraint "product_product_pkey"
SQL state: 23505
Detail: Key (id)=(700) already exists.


I ran select query on that record like this:

select * from product_product
where id=700


It returns columns with no data(data includes id too)

I tried to run update query like this:

update product_product set 
                        product_tmpl_id=700,
                        make_equip='Nikon', 
                        model_equip='Action 10x50 Lookout', 
                        name_template='Nikon Action 10x50 Lookout', 
                        serial_num_equip='671386', 
                        location_equip='40 Wall St.', 
                        issue_date_equip='5/13/2004 12:00:00 AM', 
                        issue_to_equip='',
                        remarks_equip='OM''s OFFICE', 
                        pr=62, 
                        ch=72, 
                        categ_id=502,valuation='manual periodic' where id=700;


result was:

Query returned successfully: 0 rows affected, 1 ms execution time.


i tried delete query too but same output.

Also show all data shows nothing like id 700.

I don't know why this is happening.

I re indexed and Vacuumed my table from maintenance but same result.

Plz let me know what is wrong with it.

Thanks

Edit

here is my cr

Solution

The column id is defined as SERIAL which is similar to the AUTO_INCREMENT property supported by some other databases.
So you should omit it in the INSERT statement or use the DEFAULT keyword and the new id will be generated automatically.

See section 8.1.4. Serial Types: http://www.postgresql.org/docs/9.3/static/datatype-numeric.html

Context

StackExchange Database Administrators Q#87387, answer score: 3

Revisions (0)

No revisions yet.