Chapter 5. The create table Statement

AQL has a create table statement, similar to the SQL statement by the same name. The create table statement in AQL is used to make static lookup tables for adding additional information to annotations:

create table <table name> (
        <type> <colname> [, <type> <colname> ]*
as values 
    ( <value< [, <value<]*),
    ...
    ( <value< [, <value<]*);

The following example shows the create table statement being used to add additional location metadata to company name annotations:

-- Create a dictionary of company names
create dictionary CompanyNames as
('IBM', 'Enron', 'Initech');

-- Find all matches of the company names dictionary.
create view Company as
extract
	dictionary 'CompanyNames' on D.text as company
from Document D;


-- Create a table that maps company names to locations of 
-- corporate headquarters.
create table NameToLocation (name Text, location Text) as
values 
	('IBM', 'USA'), 
	('Enron', 'Hell'), 
	('Initech', 'Dallas'),
	('Acme Fake Company Names', 'Somewhere');

-- Use the table to augment the Company view with location
-- information.
create view CompanyLoc as
select N2C.location as loc, C.company as company
from Company C, NameToLocation N2C
where Equals(GetText(C.company), GetText(N2C.name));

output view CompanyLoc;

Limitations of the Current Version

In the current version of AQL, all columns in a create table statement must be of type Text. Future versions of the language will lift this restriction.