firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Add Standard Bitwise Operators (&, |, ^, ~, <<, >>)

Open uin84101100 opened this issue 1 month ago • 8 comments

Description: Currently, Firebird lacks support for standard bitwise operators (&, |, ^, ~, <<, >>). To perform bitwise operations, users must rely on non-standard functions like BIN_AND, BIN_OR, etc.

This creates significant challenges in two main areas:

Database Migration: Migrating database logic from other systems (such as MySQL, PostgreSQL, or SQL Server) that use standard bitwise operators to Firebird requires extensive and cumbersome rewriting of SQL code. This is a major hurdle that increases migration costs and complexity.

ORM Support: Many popular Data/ORM frameworks (e.g., Entity Framework, Dapper, SQLAlchemy, and others) have built-in support for standard bitwise operators in their LINQ or query expressions. The absence of these operators in Firebird means that these ORMs cannot generate the correct SQL, leading to a lack of support or forcing developers to use raw SQL workarounds. This severely impacts developer experience and productivity when using Firebird with modern application frameworks.

Proposed Solution: We kindly request the addition of the standard bitwise operators to the Firebird SQL dialect:

& (Bitwise AND)

| (Bitwise OR)

^ (Bitwise XOR)

~ (Bitwise NOT)

<< (Bitwise Left Shift)

>> (Bitwise Right Shift)

These new operators should function identically to the existing BIN_* functions but provide a standard and familiar syntax.

Benefits:

Easier Migrations: Drastically simplifies the process of moving applications from other databases to Firebird.

Better ORM Compatibility: Enables full support for bitwise operations in various Object-Relational Mappers, making Firebird a more attractive option for modern development.

Improved Developer Experience: Allows developers to write more intuitive and portable SQL code.

Thank you for considering this feature request.

uin84101100 avatar Nov 22 '25 14:11 uin84101100

Which standard has these operators?

aafemt avatar Nov 22 '25 14:11 aafemt

Did you use AI to generate this post?

mrotteveel avatar Nov 23 '25 09:11 mrotteveel

The SQL standard does not define bitwise operators or functions. Firebird provides a set of functions for it: Bitwise Functions.

BTW: Any ORM or query generator worth its salt will be able to map to functions for this.

That said, I wouldn't mind this.

For comparison, operators like this are offered by SQL Server, PostgreSQL (though in PostgreSQL ^ is exponentiation, XOR is #), MySQL, MariaDB.

For example Oracle and DB2 don't have this, only functions.

mrotteveel avatar Nov 23 '25 10:11 mrotteveel

Did you use AI to generate this post?

Why are you question this?

asfernandes avatar Nov 23 '25 12:11 asfernandes

Did you use AI to generate this post?

Why are you question this?

Because I want to know; I find this style hard to read, and some of the arguments seem a bit spurious.

mrotteveel avatar Nov 23 '25 13:11 mrotteveel

I wouldn't rush to implement operators not included in the SQL standard. Some DBMSs are now paying the price for initially poor decisions. For example, MySQL once made the || operator similar to the OR operator for "convenience." Now, instead of the standard string concatenation operator, they have to deal with the CONCAT function.

sim1984 avatar Nov 24 '25 14:11 sim1984

I wouldn't rush to implement operators not included in the SQL standard. Some DBMSs are now paying the price for initially poor decisions. For example, MySQL once made the || operator similar to the OR operator for "convenience." Now, instead of the standard string concatenation operator, they have to deal with the CONCAT function.

Very good argument.

asfernandes avatar Nov 24 '25 15:11 asfernandes

On 11/24/25 18:37, Adriano dos Santos Fernandes wrote:

asfernandes left a comment (FirebirdSQL/firebird#8809) https://github.com/FirebirdSQL/firebird/issues/8809#issuecomment-3571433333

I wouldn't rush to implement operators not included in the SQL
standard. Some DBMSs are now paying the price for initially poor
decisions. For example, MySQL once made the |||| operator similar
to the |OR| operator for "convenience." Now, instead of the
standard string concatenation operator, they have to deal with the
|CONCAT| function.

Very good argument.

+1

Moreover, we have a lot of not implemented standard features.

AlexPeshkoff avatar Nov 24 '25 15:11 AlexPeshkoff