[CDBI] Fwd: find_or_create() barfs with constraints

Aaron Turner aturner at musecurity.com
Wed Aug 3 02:52:06 BST 2005

The exact error I get is:

DBD::Pg::st execute failed: ERROR:  duplicate key violates unique  
constraint "variant_type.name_suite"
[for Statement "INSERT INTO mucore.variant_type (name, suite_typeid,  
VALUES (?, ?, ?)
" with ParamValues: 2='3', 1='invalid-length', 3='11'] at /usr/lib/ 
perl5/site_perl/5.8.5/DBIx/ContextualFetch.pm line 51, <DIGEST> line  

The issue here of course is that variant_type.name_suite is a unique  
key on the suite_typeid and name columns, which is what I pass to  
find_or_create().  The variant_type table has a separate PK/sequence  

It appears to be that find_or_create() isn't finding the record, and  
is then trying to re-insert it.

Aaron Turner, Sr. Security Engineer                        
<aturner at musecurity.com>

On Aug 2, 2005, at 6:24 PM, Peter Speltz wrote:

> On 8/2/05, Aaron Turner <aturner at musecurity.com> wrote:
>> I'm looking to insert a record in table if it doesn't already exist.
>> I've also created a unique key (across two columns) to prevent other
>> access not via Class::DBI from causing problems.
>> The issue seems however that when I do a Object->find_or_create
>> ({ col1 => 'value', col2 => 'value'}) I get an error when it
>> apparently tries to insert a duplicate record.
> whats the error?  Are you sure it is the MK causing problem. It is
> weird that it would not find your row.
> --
> pjs

More information about the ClassDBI mailing list