-
Notifications
You must be signed in to change notification settings - Fork 6
Columns container
The ColumnsContainer abstract class models provides a common interface for classes that contain columns. In the current meta-model, three classes inherit from it:
Table: Obviously, a table contains columns as it is defined in the relational model.
View: A view can be seen as a "named select query". That is to say, it allows one to re-use a query in different parts of its database by referencing its name. Nonetheless, referencing a table or a view in a query is transparent from the developper point of view. So it seems logical that a View is a ColumnsContainer since it is possible to access its columns the same way as it is done for a Table.
DerivedTable: A derived table is a temporary table created to store temporarily the results of a sub-select query in a select query. Such tables are not globally named as a Tableor a View because they can not be accessed outside the query in which they are computed (which is also the query defining them). Nonetheless, they can get an alias to be referenced inside the query. For example, consider the following query:
SELECT beers.name, good_breweries.name
FROM beers, (SELECT id, name FROM breweries WHERE stars > 3) AS good_breweries
WHERE beers.breweryId = good_breweries.id;
In this example, (SELECT id, name FROM breweries WHERE stars > 3) AS breweries is the definition of a DerivedTable that can be referenced with its alias good_breweries. The columns contained in this DerivedTable are id and name.
It is also possible that a DerivedTable has no alias, for example:
SELECT beers.name
FROM beers
WHERE beers.id NOT IN (SELECT id FROM beers WHERE quality = 'Bad');
In this example, (SELECT id FROM beers WHERE quality = 'Bad') is the definition of a DerivedTable but this table is only used in the WHERE clause and can not be referenced anywhere else.