Is it possible to have boolean expressions in the select-clause in Firebird?

Viewed 296

In mysql you can do select name <> '' from persons where person_id = 1000 and it will return a 1 or zero, is there a way to do something similar in Firebird with DML? Based on what I've been able to determine I'm guessing not.

1 Answers

In Firebird 3 and later this is possible, as the introduction of the BOOLEAN data type now allows this type of expression in the select clause. Such a boolean expression will return true/false, although some tools might map that to 1/0 for you.

In Firebird 2.5 and earlier you will have to map this yourself, for example using CASE:

select case when name <> '' then 1 else 0 end from atable where person_id = 1000

or IIF:

select iif(name <> '', 1, 0) from atable where person_id = 1000

This also works in Firebird 3 and higher.

Related