Issue Details (XML | Word | Printable)

Key: CORE-2350
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Adriano dos Santos Fernandes
Reporter: Bill Oliver
Votes: 1
Watchers: 2

If you were logged in you would be able to see more operations.
Firebird Core

Too long column name for select alias should be rejected

Created: 03/Mar/09 10:08 PM   Updated: 15/Jun/16 10:06 PM
Component/s: Engine
Affects Version/s: 2.0.0, 1.5.4, 2.0.1, 2.0.2, 2.0.3, 1.5.5, 2.1.0, 2.0.4, 2.5 Alpha 1, 2.1.1, 2.0.5
Fix Version/s: 3.0 Beta 1

Environment: tested on windows xp, portable problem
Issue Links:

QA Status: Done successfully

 Description  « Hide

A co-worker reported this test case. The last query silently truncates the aliased column name. He thinks that an error should be raised in this case. That seems reasonable to me.

The truncated column can still be referenced by the long name. This query returns the "correct" column. This is likely because we always chop to 31 chars.

Dmitry suggested to add a tracker, with this additional information.

I'm not sure it's really truncated, because a reference via a one-char-shorter fails:

   select i2345678901234567890123456789012345 from (select i as
   i23456789012345678901234567890123456 from t1);


   select i23456789012345678901234567890123456 from (select i as
   i2345678901234567890123456789012345 from t1);

Column alias names are not part of ODS, they don't even exist at the BLR level. It's a purely parsing time thing, so I believe the parser has no need to truncate the name and always deals with longer alias names. So, technically speaking, this is not a bug.

 From another side, column alias names can be used to implicitly name the view columns and this fails:

   create view v as
   select rdb$relation_id as i23456789012345678901234567890123456
   from rdb$relations

which looks somewhat inconsistent with the above.

Besides, I suspect that the SQL spec also requires alias names to share the implementation-defined length limits with column names, table names,
etc. If so, maybe it's worth entering a request into the tracker.


create database 'test.fdb';

-- fails, table name too long
create table t23456789012345678901234567890123456 (i integer);

-- fails, column name too long
create table t1 (i23456789012345678901234567890123456 integer);

create table t1 (i integer);
-- passes, and column name is truncated to 31 characters?
select i as i23456789012345678901234567890123456 from t1;

-- this works, too. We can still reference truncated column by long name,
-- which is better than nothing, I guess.
select i23456789012345678901234567890123456 from (select i as
i23456789012345678901234567890123456 from t1);

drop database;

 All   Comments   Change History   Subversion Commits      Sort Order: Descending order - Click to sort in ascending order
Pavel Zotov added a comment - 15/Jun/16 10:06 PM
> must now be fixed.

Checked on WI-T4.0.0.254 --- all fine.

Adriano dos Santos Fernandes added a comment - 14/Jun/16 05:21 PM
Pavel, must now be fixed.

Adriano dos Santos Fernandes added a comment - 14/Jun/16 10:43 AM
Pavel, I saw it yesterday while testing CORE-5277. No need to reopen this if it is a recent regression. I'll fix it.

Pavel Zotov added a comment - 14/Jun/16 06:06 AM
Max. length of procedure and parameter names, as all other DB objects, is restricted in 4.0 to 64 characters.
But one more good news is that max length of local aliases and variable names now equals 255 (i've checked only ascii charset).

Is it expected ?

For example, following code will be compiled without error:

set term ^;
create or alter procedure p2 returns(o2 double precision) as
    select rand()*1000 as
    from rdb$database as
    o2 = sqrt(v2345678901234567890123456789012345678901234567890123456789012345b2345678901234567890123456789012345678901234567890123456789012345a2345678901234567890123456789012345678901234567890123456789012345b23456789012345678901234567890123456789012345678901234567890);
set term ;^

show procedure p2;

Workdev Tecnologia da Informação LTDA added a comment - 31/Dec/15 11:56 AM

The nickname should not have limited or at least 50 when it is used for reports where the user can edit the same columns are unrecognizable . Limitations should come in the number of database corruption and not on the user's flexibility.

Dmitry Yemanov added a comment - 18/Apr/14 12:17 PM
I cannot reproduce it on v3 anymore, suposedly it was fixed in the meantime.

Balázs Csaba added a comment - 05/May/09 01:38 PM
Field alias truncation occured very often when our framework used:

SELECT TBL27."Id" "",
       TBL27."StockOut" "stockoutsettling.stockout",
       TBL28."VoucherNumber" "stockout.vouchernumber",
       TBL27."SettleDate" "stockoutsettling.settledate",
       TBL27."CheckoutVoucherDetail" "stockoutsettling.checkoutvoucherdetail",
       TBL27."NegStockOut" "stockoutsettling.negstockout",
       TBL27."GrossValue" "stockoutsettling.grossvalue"
FROM "StockOutSettling" TBL27

Often the truncated string occurs fieldname equality, so the resultset has fewer column than the select command.