Subject Re: [firebird-support] Metadata about views
Author Ann Harrison
On Mon, Apr 7, 2014 at 6:04 AM, Svein Erling Tysvær <svein.erling.tysvaer@...> wrote:
>Maybe, I've completly mistaken the original question, but isn't
>select  r.RDB$VIEW_SOURCE
>   from RDB$RELATIONS r
>   where r.RDB$VIEW_SOURCE is not null
>simply returning the underlying query - with every field?

Yes - at least that's what it was designed to do - store the query expression that forms the view. 

Sure, it would in many cases return the query used in the view (I think it is possible to delete the RDB$VIEW_SOURCE and still have a working view, though that is rarely desirable and probably not something Łukasz has to worry about), but it doesn't return FieldNames as defined in

CREATE VIEW [ViewName]([FieldNames]) AS ...

Those field are defined in RDB$RELATION_FIELDS for the view.

just whatever is after AS.

When the system tables were being defined (33 years ago), one of my goals was to be able to recreated the language that defined the metadata from the system tables.  The working parts of the system tables would create something functionally equivalent, but the actual source was necessary for some of the fine points.  One I remember is that context variables (e.g.  the 'a' and 'b' in SELECT, from people a inner join people b where b.spouse = a.person_id and a.spouse <> b.person_id) are turned into numbers in BLR. I suppose we could have created a table that correlated the given context variable to the numeric equivalent, but storing the source was a great deal easier.