Subject Re: is where 1=0 needed?
Author Adam
> Hi all,
> I originally code it in odbc, but here I rephrase using sql jargon.
> Often I declare a cursor for inserting rows using
> select a,b,c from t
> or
> select a,b,c from t where 1=0
> Actually a cursor (statement handle) is prepared and no rows will
be fetched.
> Does the clause "where 1=0" have any significance? I found speed
for both of
> them is the same even for a large table. I would like to have some
> to drop that clause.

Well your queries are different.

The first will return ALL records in t. The second will return

Using a fixed expression like 1=0 is bad because it is evaluated for
EVERY record of t (a limitation of the FB optimiser, arguably a
feature that is pointless). If you don't want any records, don't run
the query. If you must run the query to get an empty results, then
use the PK index to eliminate all possible records.

For example, if the PK is based on a generator value, it can only
contain positive integers (well BIGINT to be precise).

So the following query will make use of the PK index and return much

select a,b,c from t where ID=0

If all values are possible, you can use two conditions to create an
impossible match, like below.

select a,b,c from t where ID=0 and ID=1