SQL queries
Create dynamic map layers in Felt using SQL queries.

Felt’s SQL query feature lets you write and execute SQL queries directly against your database, enabling you to easily visualize results from custom filters, joins and spatial analysis powered upstream. It gives you full control over how your data is displayed, ensuring your maps are tailored to meet your specific requirements. Whether you're refining data or creating complex visualizations from generated SQL results, Felt makes it easy to seamlessly integrate your custom queries with your mapping workflow.
This feature is only available to customers on the Enterprise plan. To upgrade, contact sales.
Set up
Connecting a cloud data source is required to access this feature, and SQL can only be run on the tables and views connected in your cloud source. The supported cloud sources supporting SQL queries today are:
PostGIS
Snowflake
BigQuery
Microsoft SQL Server
Databricks
Redshift
To set up a source connection, see detailed instructions on cloud sources.
Using Felt AI SQL
Felt AI SQL is a conversational interface that transforms natural language questions into optimized SQL queries across multiple cloud database platforms. It allows anyone on your team to perform complex spatial analysis without writing code or waiting for technical assistance.

Any editor in Felt can use AI to:
Perform complex spatial analysis without waiting for technical assistance

Update or edit SQL queries run in Felt

Explore data schema and table attributes in the source

Generating SQL layers
Click on the Library (toolbar) and select your data source under the
Sources
heading.Select
+ New SQL query
(or select a table and click...
>Write SQL query
).The SQL query window will open
the left side includes all the tables and views available in your source
the right side includes the SQL editor (top) and the AI prompt area (bottom) where you can provide prompts to Felt AI. Use the
Schema
andMetadata
tabs (bottom) to learn more about the structure of tables in the database.
Once Felt AI generates SQL, a preview will run automatically. Use the
Results
tab (bottom right) to review results from the SQL query in table format.Click
Create Layer
to add your data to the map.The dropdown option allows you to set the Live sync Frequency or turn Live syncs off
A new layer will be added to your map and you can start styling your results.
Editing SQL layers
You can review and edit existing layers with updated SQL either with or without AI assistance. You can edit or write queries directly within the query editor (top right).
To edit or update an existing layer built with SQL:
Select the Layer in Edit mode
Navigate to the
Data
tab in the layer menuClick on
SQL query
next toDataset

Either edit the SQL directly or use Felt AI assistant to make modifications to the query
Click
Save
to update the existing layer with the new query

Copy recent queries
The 20 most recent SQL queries that created layers on maps will appear at the top when opening a source via the Library. This will show you a history of all the queries run on maps in the account.

To re-use and fork queries other teammates have run, click on any of the entries listed under Queries
and start editing.
Debugging
Run previews by clicking on the
Preview
button (top right) to verify the SQL query is validErrors will appear in the
Results
tab (bottom right) with more detailsYou can fix errors with Felt's AI assistant by clicking
Fix errors with AI
option

Supported Spatial Operations
Different SQL platforms offer varying levels of support for spatial operations, with some providing extensive libraries of geospatial functions and others offering more basic capabilities. While some focus on advanced geographic and geometric queries, others prioritize scalability and integration with broader data processing workflows. The specific capabilities and limitations depend on the platform, so refer to the relevant documentation linked below for more details.
Postgres (PostGIS)
Example Operations
Not sure which operation to use? Ask Felt AI to run the operation for you.
ST_Intersects
Tests whether two geometries share any space in common. Returns true if geometries intersect, false otherwise. Used for identifying overlapping areas.
SELECT a.*, b.* FROM service_areas a JOIN market_zones b ON ST_Intersects(a.geometry, b.geometry);
ST_Within
Tests whether one geometry is completely inside another. Returns true if the first geometry is completely within the second geometry.
SELECT a.name, b.name FROM points a JOIN polygons b ON ST_Within(a.geometry, b.geometry);
ST_Buffer
Creates a new geometry that represents all points within a given distance from the input geometry. Useful for creating service areas or zones of influence.
SELECT location_id, ST_Buffer(geometry, 5000) as service_area FROM distribution_centers;
ST_Centroid
Computes the geometric center (centroid) of a geometry. Returns a point that represents the average position of all points in the geometry.
SELECT region_name, ST_Centroid(geometry) as center_point FROM service_regions;
ST_Distance
Calculates the shortest distance between two geometries. Returns the minimum distance between any two points in the two geometries.
SELECT a.id, b.id, ST_Distance(a.geometry, b.geometry) as distance FROM points a CROSS JOIN points b WHERE a.id != b.id;
ST_Area
Calculates the area of a polygon geometry. Returns the area in the units of the spatial reference system.
SELECT territory_id, ST_Area(geometry::geography) as area_sqm FROM market_territories;
ST_Length
Calculates the length of a linear geometry (linestring). Returns the length in the units of the spatial reference system.
SELECT route_id, ST_Length(geometry::geography) as length_meters FROM delivery_routes;
ST_Union
Combines multiple geometries into a single geometry. Dissolves overlapping boundaries and creates a single continuous geometry.
SELECT region_id, ST_Union(geometry) as combined_geometry FROM parcels GROUP BY region_id;
ST_Intersection
Returns the geometry representing the shared portions of two geometries. Creates a new geometry containing only the overlapping areas.
SELECT ST_Intersection(a.geometry, b.geometry) as overlap FROM zone_a a CROSS JOIN zone_b b;
ST_Transform
Transforms a geometry from one coordinate system to another. Used to convert between different spatial reference systems (SRS).
SELECT id, ST_Transform(geometry, 4326) as wgs84_geom FROM locations;
ST_Envelope
Computes the minimum bounding rectangle that contains a geometry. Returns a rectangular polygon that completely encloses the input geometry.
SELECT region_id, ST_Envelope(ST_Collect(geometry)) as bbox FROM market_regions GROUP BY region_id;
ST_ConvexHull
Computes the smallest convex polygon that contains all points in a geometry. Creates a shape that represents the outer boundary of a set of points.
SELECT cluster_id, ST_ConvexHull(ST_Collect(geometry)) as boundary FROM points GROUP BY cluster_id;
ST_Contains
Tests whether one geometry completely contains another. Returns true if the second geometry is completely contained within the first geometry.
SELECT points.* FROM customer_points points JOIN service_areas areas ON ST_Contains(areas.geometry, points.geometry);
Last updated
Was this helpful?