firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Using domains in definition of computed fields

Open emil-totev opened this issue 6 months ago • 3 comments

It seems it is not allowed to use domains as type for computed fields. The following test produces an error (Firebird 5.0.2 on Windows):

SQL> create domain var8 as varchar(8);
SQL>
SQL> create table test(
CON> id var8 primary key,
CON>  f1 varchar(8) computed by (id),
CON>  f2 computed by(id),
CON>  f3 var8 computed by (id)
CON>  );
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 5, column 10
-computed

It works with the generic data type and without type specification, but not with the domain. According to Mark Rotteveel on firebird-support,

The "problem" is that the grammar for computed columns uses non_array_type where it probably should be using domain_or_non_array_type_name.

If there is a special reason for that, at least the documentation should be updated to say explicitly that domains are not allowed.

emil-totev avatar Jun 27 '25 10:06 emil-totev

The "problem" is that the grammar for computed columns uses non_array_type where it probably should be using domain_or_non_array_type_name.

Not simple as that.

The computed value/source is in RDB$FIELDS, not RDB$RELATION_FIELDS.

And a field cannot be based in another field.

asfernandes avatar Jun 27 '25 11:06 asfernandes

@asfernandes So, do you suggest that the documentation should be fixed instead?

mrotteveel avatar Jun 27 '25 12:06 mrotteveel

Currently it's not accepted, so it's better to document it if not already.

asfernandes avatar Jun 30 '25 00:06 asfernandes