Subject | Re: best way to insert or update |
---|---|
Author | Adam |
Post date | 2005-06-23T00:34:39Z |
Hello Rick,
--- In firebird-support@yahoogroups.com, "Rick Debay" <rdebay@r...>
wrote:
an "insert or update" style statement, the primary key would need to be
known before the call was made. If a key was unknown, I could just
check whether the value was null and run an update if it wasn't.
In any case, I do not consider "skipped" generator values to be a
problem. Primary keys are not required to be sequential, simply unique.
I am leaning towards method 3 anyway because I do not know how
much "work" I have made FB do during that failed insert.
Here is another possible method
Method4:
select 1
from tableA
where id = :ID
into :RecordExists;
if (:RecordExists = 1) then
begin
update TableA ...
end
else
begin
insert into TableA
end;
I do not know whether this has any performance pros / cons over method
3 though?
Adam
--- In firebird-support@yahoogroups.com, "Rick Debay" <rdebay@r...>
wrote:
> If you have a trigger and generator doing auto-key generation, methoduse
> two will use up a key with every failed insert. Because of this we
> method three.We do not use ours trigger to generate keys. But using the concept of
an "insert or update" style statement, the primary key would need to be
known before the call was made. If a key was unknown, I could just
check whether the value was null and run an update if it wasn't.
In any case, I do not consider "skipped" generator values to be a
problem. Primary keys are not required to be sequential, simply unique.
I am leaning towards method 3 anyway because I do not know how
much "work" I have made FB do during that failed insert.
Here is another possible method
Method4:
select 1
from tableA
where id = :ID
into :RecordExists;
if (:RecordExists = 1) then
begin
update TableA ...
end
else
begin
insert into TableA
end;
I do not know whether this has any performance pros / cons over method
3 though?
Adam