Subject Re: [firebird-support] retrieving info for view columns
Author Ann W. Harrison
Michael Apessos wrote:

>
> My problem is when the RELATION is a VIEW. In that case, both
> RDB$CHARACTER_LENGTH and RDB$FIELD_PRECISION
> from RDB$FIELDS are NULL.
>
> Is there a way to get that information for view columns too?
>

You'll need to use a different query for views, and include the table
rdb$view_relations. The field definitions in a view derive from the
field definitions in the base tables. The field rdb$view_context plus
the name of the view are the join terms between rdb$relation_fields and
rdb$view_relations.


This is approximately the query that will get field characteristics for
work for views that include only base tables. If you have views of
views, you'll need to apply the query recursively until you get back to
base tables.

select f rdb$field_length, f.rdb$field_type
from rdb$relation_fields v_rfr
join rdb$view_relations vr
on v_rfr.rdb$relation_name = vr.rdb$view_name
and v_rfr.rdb$view_context = vr.rdb$view_context
join rdb$relation_fields r_rfr
on vr.rdb$relation_name = r_rfr.rdb$relation_name
and v_rfr.rdb$base_field = r_rfr.rdb$field_name
join rdb$fields f on (f.rdb$field_name = r_rfr.rdb$field_source)

where v_rfr.rdb$field_name = 'my_field'
and v_rfr.rdb$relation_name = 'my_view';



Regards,


Ann