Unfortunately, Firebird does not allow you to conditionally drop or create an index in its SQL dialect. If you are executing per statement, you could catch errors and ignore the relevant error codes. Alternatively, you could use an execute block, something like:
execute block as
begin
if (exists(select * from rdb$indices where rdb$index_name = 'IDX_TABLE')) then
execute statement 'drop index IDX_TABLE';
end
The use of execute statement
is necessary, because PSQL (the Firebird procedural language) does not support DDL statements directly.
If instead you want to conditionally create an index, you can use:
execute block as
begin
if (not exists(select * from rdb$indices where rdb$index_name = 'IDX_TABLE')) then
execute statement 'create index IDX_TABLE on table (id, name)';
end
The RDB$INDICES
table is a Firebird system table.