Subject Re: [firebird-support] using select count(*)
Author Helen Borrie
At 08:50 AM 18/04/2006, you wrote:
>In our triggers and stored procedures we use
>
>select count(*)
>from table
>where value = Primary Key.value
>
>to determine whether we should run an insert or an update
>query on triggered tables.

Good grief, this sounds pretty flaky from the point of view of consistency!


>Is there a faster way?
>
>I am half way through Helen's book "The firebird book"

Read more. :-)


>She suggests never using select count(*) but I do not know a
>faster way of doing this.

In PSQL:

if exists (select 1 from atable where <something unique> then ...

In your application (if you must do this kind of test) write a
function that makes the equivalent test and returns 1 for a true
result and returns no rows otherwise:

select 1 from rdb$database where exists<something unique>

But, really, a SP is a much better way to do this two-sided stuff,
where your app doesn't know whether it's going to insert or update.

./heLen