firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Defined names does not work in WHERE/HAVING clause

Open MarvinKlein1508 opened this issue 3 years ago • 3 comments

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.

MarvinKlein1508 avatar Jun 24 '21 10:06 MarvinKlein1508

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

aafemt avatar Jun 24 '21 10:06 aafemt

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

It counts only one time.

asfernandes avatar Jun 24 '21 11:06 asfernandes

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

frafor avatar Oct 30 '21 23:10 frafor