Common queries

As you connect to the database, you will be able to retrieve data via SQL queries. This section provides sample SQL queries to help you start working with the Private Telematics Lakehouse. These examples demonstrate how to access and analyze data from the Bronze layer, which contains raw business and telematic data with minimal transformation.

Basic queries

Retrieve basic object information

This query returns information about objects (vehicles/assets) in your system:

SELECT
    o.object_id,
    o.object_label,
    o.model,
    d.device_imei,
    g.group_label
FROM
    raw_business_data.objects o
    LEFT JOIN raw_business_data.devices d ON o.device_id = d.device_id
    LEFT JOIN raw_business_data.groups g ON o.group_id = g.group_id
WHERE
    o.is_deleted = false
ORDER BY
    o.object_label;

Get latest device locations

Retrieve the most recent location data for all your devices:

Coordinate values are stored as integers scaled by 10^7 for improved storage efficiency in TimescaleDB. When querying, divide by 10000000 to convert back to standard decimal format.

Joining business and telematic data

Vehicle activity report

This query generates a daily activity summary by joining business and telematic data:

Driver assignments and location history

Track which employees were assigned to which vehicles and their location history:

Analyzing sensor data

Fuel level tracking

This query shows how to analyze fuel sensor data:

Geospatial analysis

Vehicles in geozones

Identify which vehicles entered specific geozones:

This query uses PostGIS spatial functions. If you encounter errors, verify that PostGIS extension is enabled in your database.

Performance optimization tips

When working with the Cloud Data Warehouse, consider these optimization techniques:

  1. Use time-based filtering: Always include a time filter on the device_time or record_added_at columns to limit the data scanned. Good practice:

Avoid this (scans entire table)

  1. Leverage indexes: The database has indexes on (device_id, device_time) pairs. Structure your queries to use these indexes when possible.

  2. Use joins selectively: Join tables only when necessary and try to filter data before joining large tables.

  3. Scale integer conversion: Remember that coordinate data is stored as scaled integers. Convert only in the final SELECT, not in WHERE clauses.

  4. Limit result sets: Always use LIMIT for exploratory queries to avoid returning millions of rows.

  1. Utilize hierarchical relationships: Structure complex queries following the entity hierarchy (dealer → client → user/device → object) for more efficient joins and filtering.

  2. Manage connections properly: Close database connections when they're not in use, especially in BI tools or scheduled scripts, to avoid resource locking or timeout issues.

Next steps

These examples provide a starting point for working with your data. As you become more familiar with the schema, you can develop more complex queries to meet your specific business needs.

Last updated

Was this helpful?