If you want to access external data that is not provided through the standard YQL set of
tables (accessible through the show tables query), YQL provides the
use statement when you want to import external tables defined through your Open
Data Table definition.
You can access a single Open Data Table using the
USE
and
AS
verbs:
The AS verb in the above example is optional. If you omit the
AS verb, YQL uses the filename (without the .xml file ending) to
name the table.
In the above query, USE precedes the location of the Open Data Table
definition, which is then followed by AS and the table as defined within your
Open Data Table definition. After the semicolon, the query is formed as would be any other YQL
query. YQL fetches the URL above and makes it available as a table named mytable in the current request scope. The statements following use can then select
or describe the particular table using the name mytable.
You can also specify multiple Open Data Tables by using multiple USE
statements in the following manner:
An easier way to use multiple Open Data Tables is to write or use a YQL environment
file, which allows you to use multiple tables at once without the USE verb in
your YQL statements.
An environment file is simply a text file that contains a list of USE and
SET statements, typically ending with a ".env" suffix.
Here is how an environment file can look:
The AS verb in the above example is optional. If you omit the
AS verb, YQL uses the filename (without the .xml file ending) to
name the table.
Once you upload the environment file to your server, you can simply access the YQL console and append the location of the file as follows:
http://developer.yahoo.com/yql/console/?env=http://datatables.org/alltables.env
Try this example in the YQL console
You can include multiple environment files at once by using multiple “env” query parameters. These are loaded in the order they appear in the query string.
Advanced YQL users can better organize their Open Data Tables by nesting environment files within other environment files. For example, you can group similar tables into different environments and include each environment in a main (root) environment file as necessary. In addition to invoking environments, you can apply any SET statements to environments you invoke.
The following example both invokes multiple environments within a root environment file,
YQL processes environment files using an in-order traversal. In the example diagram above:
USE statements and then including other environments.
SET statements can be called only on tables defined in either the
defining environment or any of it parents. For example,
in the example above, sets in (A)/(B)/(C) can apply to tables defined in (C).
SET statements do not work across environments or across peers. For
example, in the above example, (D) cannot set a key on tables defined in (B) or
(C).
SET statements.
SET statements are scoped and the farthest parent with the most
appropriate table prefix match wins.