Skip to content
Advertisement

Finding computed fields in Firebird 2.5

Computed fields are readonly. I need to find all such fields in specific table.

This query solves this problem (returns info if column is computed or not):

select r.rdb$field_name, r.rdb$update_flag
from rdb$relation_fields r
where r.rdb$relation_name = 'specific_table'

At least it looks like it solves it, but it seems that returned informations are incorrect.

When RDB$UPDATE_FLAG is 0, its computed (readonly). But its 0 even for normal columns.

Advertisement

Answer

If you wanted computed fields instead – that is what you have to query for, the expression used to compute.

RDB$FIELDS stores definitions of columns and domains, both system and custom. This is where the detailed data attributes are stored for all columns.

The column RDB$FIELDS.RDB$FIELD_NAME links to RDB$RELATION_FIELDS.RDB$FIELD_SOURCE

RDB$COMPUTED_BLR – The binary language representation (BLR) of the SQL expression the database server uses for evaluation when accessing a COMPUTED BY column

https://www.firebirdsql.org/file/documentation/html/en/refdocs/fblangref25/firebird-25-language-reference.html#fblangref-appx04-fields

Hence, something like this should work:

select r.rdb$field_name --, r.rdb$update_flag
from rdb$relation_fields r, RDB$FIELDS f
where r.rdb$relation_name = 'specific_table'
  and f.RDB$FIELD_NAME = r.RDB$FIELD_SOURCE
  and f.RDB$COMPUTED_BLR is not NULL

P.S. https://github.com/FirebirdSQL/firebird-documentation/issues/157

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement