FirebirdSQL / firebird

Firebird server, client and tools
https://www.firebirdsql.org/
1.24k stars 215 forks source link

Defined names does not work in WHERE/HAVING clause #6870

Open MarvinKlein1508 opened 3 years ago

MarvinKlein1508 commented 3 years ago

Why does Firebird cannot work with custom aliases for column names in where and having clauses? This is a major lack of functionality because you need to write the same code twice.

Not sure about the performance aspect but doesn't it count(*) twice now instead of just one time?

SELECT BSTU_N_BELEPOSID, COUNT(*) AS AMOUNT 
FROM BELEGSTUECKLISTE WHERE BSTU_N_BELEPOSID = 344209
GROUP BY BSTU_N_BELEPOSID
HAVING AMOUNT > 3

Throws exception: Dynamic SQL Error SQL error code = -206 Column unknown AMOUNT At line 4, column 8

Instead:

SELECT BSTU_N_BELEPOSID, COUNT(*) AS AMOUNT 
FROM BELEGSTUECKLISTE WHERE BSTU_N_BELEPOSID = 344209
GROUP BY BSTU_N_BELEPOSID
HAVING COUNT(*) > 3

Using the custom aliases works in every other major DBMS, e.g. MySQL.

aafemt commented 3 years ago

SQL Fiddle insists that it works ONLY in MySQL and no other DBMS.

asfernandes commented 3 years ago

Not sure about the performance aspect but doesn't it count(*) twice now instead of just one time?

It counts only one time.

frafor commented 2 years ago

It would be great if the alias could be used. Will it ever be possible?