ποΈSQL Database
Table Naming
When loading data into the database, messages will be sorted into SQL tables determined by the message type and month. The names of these tables follow the following format, which {YYYYMM}
indicates the table year and month in the format YYYYMM.
Some additional tables containing computed data may be created depending on the indexes used. For example, an aggregate of vessel static data by month or a virtual table is used as a covering index.
Additional tables are also included for storing data not directly derived from AIS message reports.
For quick reference to data types and detailed explanations of these table entries, please see the Detailed Table Description.
Custom SQL Queries
In addition to querying the database using DBQuery
module, there is an option to customize the query with your own SQL code.
Example of listing all the tables in your database:
As messages are separated into tables by message type and month, queries spanning multiple message types or months should use UNIONs and JOINs to combine results as appropriate.
Example of querying tables with `JOIN`:
More information about SQL queries can be looked up from online tutorials.
The R* tree virtual tables should be queried for AIS position reports instead of the default tables. Query performance can be significantly improved using the R* tree index when restricting output to a narrow range of MMSIs, timestamps, longitudes, and latitudes. However, querying a wide range will not yield much benefit. If custom indexes are required for specific manual queries, these should be defined on message tables 1_2_3, 5, 18, and 24 directly instead of upon the virtual tables.
Timestamps are stored as epoch minutes in the database. To facilitate querying the database manually, use the dt_2_epoch()
function to convert datetime values to epoch minutes and the epoch_2_dt()
function to convert epoch minutes back to datetime values. Here is how you can use dt_2_epoch()
with the example above:
For more examples, please see the SQL code in aisdb_sql/
that is used to create database tables and associated queries.
Detailed Table Description
ais_{YYYYMM}_dynamic
tables
ais_{YYYYMM}_dynamic
tablesais_{YYYYMM}_static
tables
ais_{YYYYMM}_static
tables static_{YYYYMM}_aggregate
tables
static_{YYYYMM}_aggregate
tablesLast updated