Subject Re: [firebird-support] Inserting records where primary key exists (opinion)
Author David Johnson
It is better to insert and catch the exception if you have a large
number of records.

If you insert and catch the exception, the lookup happens once and then
you write the new row. Your performance remains nearly flat whether you
write or throw the exception.

If you query first, then you do the lookup once, do the same lookup, and
then write the new row. Query first should be a bit less than 1/2 the
speed (just over twice the time) as insert and ignore, with some
allowance for page caching.


On Tue, 2005-03-15 at 02:30, rodbracher wrote:
>
>
>
> Hi
>
> If I can expect to have certain records inserted, but the primary key
> already exists, is it ok to get the exception and ignore the insert.
>
> OR
>
> Is it better practice to query the db, check if the record exists, if
> it does ignore the insert.
>
> (Its a case where I never want to update a record if it has been
> inserted already.)
>
> I know either way will work, it just seems like the second option may
> create more 'work' for the database - or is it the other way around?
>
> Thanks
>
> Rod
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>