Subject Re: [firebird-support] Select * from where 0=1
Author Lucas Franzen
Jerome Bouvattier schrieb:

> Hello list,
>
> I need to retrieve an empty resultset with all fields of a given table. I
> tried the two following queries :
>
> #1 : Select * from <table> where 0=1
> #2 : Select first 0 * from <TableName>
>
> First one seems to care about the amount of data in the queried table, while
> the second one does not.
>
> Against an empty table, both queries perform the same.
> On a 15 million table, #1 takes 1.8s while #2 takes 20ms.
>
> I need to come up with a statement that's as fast a #2 but also works on
> most IB/FB engines.
> How should this statement look like ?

Another idea:

If you have only positive PrimaryKey Values (since generators are
initialized with 0), maybe a statement like:
SELECT * FROM <table> where <pk_field> = -1
will help.

Luc.