Skip to content

Socrata

Any Socrata (Tyler Data & Insights) portal's catalog and datasets as SQL, with SoQL pushdown

Connector software
Free and open source
Service credentials
Optional
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/socrata/index.md to help me query Socrata with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

The five most viewed NYC datasets about 311 service requests

Example output · captured
Connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT dataset_id, title, page_views_last_month
FROM socrata.main.datasets('data.cityofnewyork.us', q := '311 service requests')
ORDER BY page_views_last_month DESC, dataset_id
LIMIT 5
Result
dataset_id title page_views_last_month
ygpa-z7cr Housing Maintenance Code Complaints and Problems 808,967
erm2-nwe9 311 Service Requests from 2020 to Present 34,596
76ig-c548 311 Service Requests from 2010 to 2019 1837
cs9t-e3x8 311 Service Level Agreements 578
8sdw-8vja Asset Management Parks System (AMPS) - Work Orders 449

Quick start

Choose where to run Socrata, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'socrata' AS socrata (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-socrata-worker'
);

3. Add service credentials (optional)

Works without a token; an app token raises the portal's rate limits. Replace the placeholders with your service settings.

socrata credentials

Socrata app token (and optional base_url) for the portal hosts in the secret's SCOPE.

Get these credentials →
secret.sql
CREATE SECRET socrata (
    TYPE socrata,
    app_token '<APP_TOKEN>',  -- secret
    base_url  '<base_url>'
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT dataset_id, title, page_views_last_month
FROM socrata.main.datasets('data.cityofnewyork.us', q := '311 service requests')
ORDER BY page_views_last_month DESC, dataset_id
LIMIT 5
More example queries →
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'socrata' AS socrata (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-socrata-worker'
);

Overview

Any Socrata (Tyler Data & Insights) open-data portal as SQL: search portal catalogs and read typed dataset rows, with filters, projections and aggregates pushed down as SoQL. No key needed for public data.

Catalog

Everything socrata exposes once attached — read straight from the worker's released build.

socrata 1 schema
main 7 functions

Socrata catalog discovery, dataset rows and server-side SoQL.

Schema examples (14)
Examples (14)

The five most viewed NYC datasets about 311 service requests

SELECT dataset_id, title, page_views_last_month
FROM socrata.main.datasets('data.cityofnewyork.us', q := '311 service requests')
ORDER BY page_views_last_month DESC, dataset_id
LIMIT 5;
Result
dataset_id title page_views_last_month
ygpa-z7cr Housing Maintenance Code Complaints and Problems 808,967
erm2-nwe9 311 Service Requests from 2020 to Present 34,596
76ig-c548 311 Service Requests from 2010 to 2019 1837
cs9t-e3x8 311 Service Level Agreements 578
8sdw-8vja Asset Management Parks System (AMPS) - Work Orders 449

Datasets per category on the Dutch vehicle authority (RDW) portal, an EU portal

SELECT category, count(*) AS datasets
FROM socrata.main.datasets('opendata.rdw.nl')
GROUP BY category
ORDER BY datasets DESC, category;

Ten police use-of-force datasets from any US portal

SELECT portal, dataset_id, title
FROM socrata.main.search_datasets('police use of force', max_rows := 10)
ORDER BY portal, dataset_id;

Which European portals publish datasets about vehicles ('voertuigen')

SELECT portal, count(*) AS datasets
FROM socrata.main.search_datasets('voertuigen', region := 'eu', max_rows := 50)
GROUP BY portal
ORDER BY datasets DESC, portal;
10 more examples

Field names and types of NYC 311 service requests

SELECT field_name, data_type, duckdb_type
FROM socrata.main.dataset_columns('data.cityofnewyork.us', 'erm2-nwe9')
WHERE NOT is_system
ORDER BY position;

How many columns of each Socrata type the Chicago crimes dataset has

SELECT data_type, count(*) AS columns
FROM socrata.main.dataset_columns('data.cityofchicago.org', 'ijzp-q8t2')
GROUP BY data_type
ORDER BY columns DESC, data_type;

NYC 311 complaint types in Brooklyn in the first ten minutes of 2024 (filters run on the portal)

SELECT complaint_type, count(*) AS requests
FROM socrata.main.dataset('data.cityofnewyork.us', 'erm2-nwe9')
WHERE created_date >= TIMESTAMP '2024-01-01 00:00:00' AND created_date < TIMESTAMP '2024-01-01 00:10:00' AND borough = 'BROOKLYN'
GROUP BY complaint_type
ORDER BY requests DESC, complaint_type;

Chicago public library branches whose name starts with 'Ch', with website and coordinates

SELECT branch_, website.url AS website, location.latitude,
  location.longitude
FROM socrata.main.dataset('data.cityofchicago.org', 'x8fc-8rcq')
WHERE starts_with(branch_, 'Ch')
ORDER BY branch_;

NYC 311 requests per borough on 1 January 2024, counted by the portal

SELECT borough, requests::BIGINT AS requests
FROM socrata.main.soql('data.cityofnewyork.us', 'erm2-nwe9', 'SELECT borough, count(*) AS requests WHERE created_date >= ''2024-01-01T00:00:00'' AND created_date < ''2024-01-02T00:00:00'' GROUP BY borough ORDER BY borough')
ORDER BY borough;

The five crime types with the most arrests in Chicago on 1 January 2024

SELECT primary_type, arrests::BIGINT AS arrests
FROM socrata.main.soql('data.cityofchicago.org', 'ijzp-q8t2', 'SELECT primary_type, count(*) AS arrests WHERE arrest = true AND date >= ''2024-01-01T00:00:00'' AND date < ''2024-01-02T00:00:00'' GROUP BY primary_type ORDER BY arrests DESC, primary_type LIMIT 5')
ORDER BY arrests DESC, primary_type;

Quote a value containing an apostrophe for a SoQL condition

SELECT socrata.main.soql_quote('O''Brien') AS literal;

Use a quoted literal inside a raw SoQL condition

SELECT count(*) AS requests
FROM socrata.main.dataset('data.cityofnewyork.us', 'erm2-nwe9', soql_where := 'agency = ' || socrata.main.soql_quote('NYPD') || ' AND created_date >= ''2024-01-01T00:00:00'' AND created_date < ''2024-01-01T00:10:00''');

Escape LIKE wildcards in a literal value

SELECT socrata.main.soql_like_escape('100%_done') AS pattern;

NYC 311 noise complaints in the first hour of 2024, matched on the portal

SELECT descriptor, count(*) AS requests
FROM socrata.main.dataset('data.cityofnewyork.us', 'erm2-nwe9', soql_where := 'upper(descriptor) like ' || socrata.main.soql_quote('%' || socrata.main.soql_like_escape('NOISE') || '%') || ' AND created_date >= ''2024-01-01T00:00:00'' AND created_date < ''2024-01-01T01:00:00''')
GROUP BY descriptor
ORDER BY requests DESC, descriptor;
Scalar functions
soql_like_escape (text VARCHAR) 3 examples

Escape %, _ and backslash so text matches literally inside a SoQL like pattern

Arguments
text VARCHAR
Text to escape; NULL in, NULL out.
ReturnsVARCHAR
Examples (3)

Escape LIKE wildcards in a literal value

SELECT socrata.main.soql_like_escape('100%_done') AS pattern;

NYC 311 noise complaints in the first hour of 2024, matched on the portal

SELECT descriptor, count(*) AS requests
FROM socrata.main.dataset('data.cityofnewyork.us', 'erm2-nwe9', soql_where := 'upper(descriptor) like ' || socrata.main.soql_quote('%' || socrata.main.soql_like_escape('NOISE') || '%') || ' AND created_date >= ''2024-01-01T00:00:00'' AND created_date < ''2024-01-01T01:00:00''')
GROUP BY descriptor
ORDER BY requests DESC, descriptor;
SELECT socrata.main.soql_quote('%' || socrata.main.soql_like_escape('50%') || '%') AS pattern;
Link
soql_quote (value VARCHAR) 3 examples

Quote text as a SoQL string literal for soql_where := and soql() queries

Arguments
value VARCHAR
Text to quote; NULL in, NULL out.
ReturnsVARCHAR
Examples (3)

Quote a value containing an apostrophe for a SoQL condition

SELECT socrata.main.soql_quote('O''Brien') AS literal;

Use a quoted literal inside a raw SoQL condition

SELECT count(*) AS requests
FROM socrata.main.dataset('data.cityofnewyork.us', 'erm2-nwe9', soql_where := 'agency = ' || socrata.main.soql_quote('NYPD') || ' AND created_date >= ''2024-01-01T00:00:00'' AND created_date < ''2024-01-01T00:10:00''');
SELECT 'borough = ' || socrata.main.soql_quote(b) AS condition
FROM (VALUES ('BRONX'), ('QUEENS')) t(b)
ORDER BY b;
Link
Table functions
dataset (portal VARCHAR, dataset_id VARCHAR, page_rows := BIGINT, soql_where := VARCHAR) 2 examples

Rows of one Socrata dataset, typed from its metadata, with SoQL pushdown

Positional arguments
portal VARCHAR
The Socrata (Tyler Data & Insights) portal: a domain such as 'data.cityofnewyork.us', 'data.cityofchicago.org' or 'opendata.rdw.nl', or an https:// URL (a pasted dataset page URL is trimmed to the portal root).
dataset_id VARCHAR
The dataset's four-by-four id, as returned by datasets() and shown at the end of its page URL, e.g. 'erm2-nwe9'.
Named arguments
page_rows := BIGINT
Rows per request (1 to 50,000; default 1,000). Each page is one keyset step ordered by :id. · default 1000
soql_where := VARCHAR
Extra raw SoQL condition ANDed into $where, for what SQL filters cannot express server-side, e.g. 'within_circle(location, 40.75, -73.98, 500)' or "upper(descriptor) like '%NOISE%'". · default null
Returns columns
<number / money / percent column> DECIMAL(28,10)
Exact number; NULL if it needs more than 18 integer digits.
<double column> DOUBLE
Floating-point number.
<checkbox column> BOOLEAN
Checkbox.
<calendar_date / floating_timestamp column> TIMESTAMP
Local (floating) date and time.
<fixed_timestamp column> TIMESTAMPTZ
Absolute timestamp, UTC.
<point / line / polygon / multi* column> JSON
GeoJSON geometry (use ST_GeomFromGeoJSON).
<location column> STRUCT of 6 fields
Legacy location.
STRUCT 6 fields
  • latitudeDOUBLE
  • longitudeDOUBLE
  • addressVARCHAR
  • cityVARCHAR
  • stateVARCHAR
  • zipVARCHAR
<url column> STRUCT(url VARCHAR, description VARCHAR)
Link.
<phone column> STRUCT(phone_number VARCHAR, phone_type VARCHAR)
Phone number.
<text column> VARCHAR
Text and any other type.
soda_row_id VARCHAR
System row id (:id), the paging cursor.
Returns columns · depends on the arguments
<number / money / percent column> DECIMAL(28,10)
Exact number; NULL if it needs more than 18 integer digits.
<double column> DOUBLE
Floating-point number.
<checkbox column> BOOLEAN
Checkbox.
<calendar_date / floating_timestamp column> TIMESTAMP
Local (floating) date and time.
<fixed_timestamp column> TIMESTAMPTZ
Absolute timestamp, UTC.
<point / line / polygon / multi* column> JSON
GeoJSON geometry (use ST_GeomFromGeoJSON).
<location column> STRUCT of 6 fields
Legacy location.
STRUCT 6 fields
  • latitudeDOUBLE
  • longitudeDOUBLE
  • addressVARCHAR
  • cityVARCHAR
  • stateVARCHAR
  • zipVARCHAR
<url column> STRUCT(url VARCHAR, description VARCHAR)
Link.
<phone column> STRUCT(phone_number VARCHAR, phone_type VARCHAR)
Phone number.
<text column> VARCHAR
Text and any other type.
soda_row_id VARCHAR
System row id (:id), the paging cursor.
Examples (2)

NYC 311 complaint types in Brooklyn in the first ten minutes of 2024 (filters run on the portal)

SELECT complaint_type, count(*) AS requests
FROM socrata.main.dataset('data.cityofnewyork.us', 'erm2-nwe9')
WHERE created_date >= TIMESTAMP '2024-01-01 00:00:00' AND created_date < TIMESTAMP '2024-01-01 00:10:00' AND borough = 'BROOKLYN'
GROUP BY complaint_type
ORDER BY requests DESC, complaint_type;

Chicago public library branches whose name starts with 'Ch', with website and coordinates

SELECT branch_, website.url AS website, location.latitude,
  location.longitude
FROM socrata.main.dataset('data.cityofchicago.org', 'x8fc-8rcq')
WHERE starts_with(branch_, 'Ch')
ORDER BY branch_;
Link
dataset_columns (portal VARCHAR, dataset_id VARCHAR) 2 examples

Columns of a Socrata dataset with their Socrata and DuckDB types

Arguments
portal VARCHAR
The Socrata (Tyler Data & Insights) portal: a domain such as 'data.cityofnewyork.us', 'data.cityofchicago.org' or 'opendata.rdw.nl', or an https:// URL (a pasted dataset page URL is trimmed to the portal root).
dataset_id VARCHAR
The dataset's four-by-four id, as returned by datasets() and shown at the end of its page URL, e.g. 'erm2-nwe9'.
Returns columns
portal VARCHAR
Base URL of the portal.
dataset_id VARCHAR
Four-by-four dataset id.
position INTEGER
1-based position of the column in the dataset.
field_name VARCHAR
Field name: the column name in dataset() and in SoQL.
display_name VARCHAR
Human-readable column name.
description VARCHAR
Column description, when the publisher wrote one.
data_type VARCHAR
Socrata data type: text, number, calendar_date, checkbox, point, location, url, ...
duckdb_type VARCHAR
The DuckDB type of the column in dataset() (NULL for system columns).
is_system BOOLEAN
True for system and computed-region columns (field names starting with ':'), not returned by dataset().
Examples (2)

Field names and types of NYC 311 service requests

SELECT field_name, data_type, duckdb_type
FROM socrata.main.dataset_columns('data.cityofnewyork.us', 'erm2-nwe9')
WHERE NOT is_system
ORDER BY position;

How many columns of each Socrata type the Chicago crimes dataset has

SELECT data_type, count(*) AS columns
FROM socrata.main.dataset_columns('data.cityofchicago.org', 'ijzp-q8t2')
GROUP BY data_type
ORDER BY columns DESC, data_type;
Link
datasets (portal VARCHAR, asset_type := VARCHAR, category := VARCHAR, max_rows := BIGINT, q := VARCHAR, region := VARCHAR, tag := VARCHAR) 2 examples

Datasets published on a Socrata portal, from the Discovery API (US and EU)

Positional arguments
portal VARCHAR
The Socrata (Tyler Data & Insights) portal: a domain such as 'data.cityofnewyork.us', 'data.cityofchicago.org' or 'opendata.rdw.nl', or an https:// URL (a pasted dataset page URL is trimmed to the portal root).
Named arguments
asset_type := VARCHAR
Asset type to list: 'dataset' (default), 'map', 'chart', 'filter', 'file', 'href', or 'all'. · default "dataset"
category := VARCHAR
Only datasets in this portal category, e.g. 'Transportation'. · default null
max_rows := BIGINT
Stop after this many datasets (at most 10,000). · default 10000
q := VARCHAR
Full-text search over titles, descriptions, columns, tags. · default null
region := VARCHAR
Discovery API region: 'us', 'eu', or 'auto' (default: whichever index knows the portal). · default "auto"
tag := VARCHAR
Only datasets with this portal tag, e.g. '311'. · default null
Returns columns
portal VARCHAR
Base URL of the portal the dataset belongs to, e.g. https://data.cityofnewyork.us.
dataset_id VARCHAR
Four-by-four dataset id, the key for dataset(), dataset_columns() and soql().
title VARCHAR
Dataset title.
description VARCHAR
Dataset description as plain text (HTML tags removed).
asset_type VARCHAR
Asset type: dataset, map, chart, filter (a saved view), file, href, ...
category VARCHAR
The portal's category for the dataset, e.g. 'Social Services'.
tags VARCHAR[]
The portal's tags for the dataset.
publisher VARCHAR
Attribution: the agency or organization that publishes the data.
owner VARCHAR
Display name of the portal account that owns the dataset.
license VARCHAR
License name, when the portal records one.
provenance VARCHAR
'official' or 'community'.
created TIMESTAMPTZ
When the dataset was created on the portal (UTC).
modified TIMESTAMPTZ
When the dataset (data or metadata) last changed (UTC).
data_updated TIMESTAMPTZ
When the rows last changed (UTC).
metadata_updated TIMESTAMPTZ
When the metadata last changed (UTC).
page_views_last_month BIGINT
Page views in the last month.
page_views_total BIGINT
Page views since publication.
download_count BIGINT
Number of downloads, when reported.
column_names VARCHAR[]
Field names of the dataset's columns (system columns excluded).
domain_metadata STRUCT(key VARCHAR, value VARCHAR)[]
Portal-specific metadata fields as (key, value) pairs.
url VARCHAR
The dataset's page on the portal: <portal>/d/<dataset_id>.
api_url VARCHAR
SODA endpoint: <portal>/resource/<dataset_id>.json.
Examples (2)

The five most viewed NYC datasets about 311 service requests

SELECT dataset_id, title, page_views_last_month
FROM socrata.main.datasets('data.cityofnewyork.us', q := '311 service requests')
ORDER BY page_views_last_month DESC, dataset_id
LIMIT 5;
Result
dataset_id title page_views_last_month
ygpa-z7cr Housing Maintenance Code Complaints and Problems 808,967
erm2-nwe9 311 Service Requests from 2020 to Present 34,596
76ig-c548 311 Service Requests from 2010 to 2019 1837
cs9t-e3x8 311 Service Level Agreements 578
8sdw-8vja Asset Management Parks System (AMPS) - Work Orders 449

Datasets per category on the Dutch vehicle authority (RDW) portal, an EU portal

SELECT category, count(*) AS datasets
FROM socrata.main.datasets('opendata.rdw.nl')
GROUP BY category
ORDER BY datasets DESC, category;
Link
search_datasets (q VARCHAR, asset_type := VARCHAR, category := VARCHAR, max_rows := BIGINT, region := VARCHAR, tag := VARCHAR) 2 examples

Search datasets across every Socrata portal of a region (Discovery API)

Positional arguments
q VARCHAR
Full-text search across every portal, e.g. 'police use of force'.
Named arguments
asset_type := VARCHAR
Asset type: 'dataset' (default), 'map', 'chart', ..., or 'all'. · default "dataset"
category := VARCHAR
Only datasets in this category. · default null
max_rows := BIGINT
Stop after this many results (default 100, at most 10,000). · default 100
region := VARCHAR
Which federated index to search: 'us' (default, US portals) or 'eu' (European portals). · default "us"
tag := VARCHAR
Only datasets with this tag. · default null
Returns columns
portal VARCHAR
Base URL of the portal the dataset belongs to, e.g. https://data.cityofnewyork.us.
dataset_id VARCHAR
Four-by-four dataset id, the key for dataset(), dataset_columns() and soql().
title VARCHAR
Dataset title.
description VARCHAR
Dataset description as plain text (HTML tags removed).
asset_type VARCHAR
Asset type: dataset, map, chart, filter (a saved view), file, href, ...
category VARCHAR
The portal's category for the dataset, e.g. 'Social Services'.
tags VARCHAR[]
The portal's tags for the dataset.
publisher VARCHAR
Attribution: the agency or organization that publishes the data.
owner VARCHAR
Display name of the portal account that owns the dataset.
license VARCHAR
License name, when the portal records one.
provenance VARCHAR
'official' or 'community'.
created TIMESTAMPTZ
When the dataset was created on the portal (UTC).
modified TIMESTAMPTZ
When the dataset (data or metadata) last changed (UTC).
data_updated TIMESTAMPTZ
When the rows last changed (UTC).
metadata_updated TIMESTAMPTZ
When the metadata last changed (UTC).
page_views_last_month BIGINT
Page views in the last month.
page_views_total BIGINT
Page views since publication.
download_count BIGINT
Number of downloads, when reported.
column_names VARCHAR[]
Field names of the dataset's columns (system columns excluded).
domain_metadata STRUCT(key VARCHAR, value VARCHAR)[]
Portal-specific metadata fields as (key, value) pairs.
url VARCHAR
The dataset's page on the portal: <portal>/d/<dataset_id>.
api_url VARCHAR
SODA endpoint: <portal>/resource/<dataset_id>.json.
Examples (2)

Ten police use-of-force datasets from any US portal

SELECT portal, dataset_id, title
FROM socrata.main.search_datasets('police use of force', max_rows := 10)
ORDER BY portal, dataset_id;

Which European portals publish datasets about vehicles ('voertuigen')

SELECT portal, count(*) AS datasets
FROM socrata.main.search_datasets('voertuigen', region := 'eu', max_rows := 50)
GROUP BY portal
ORDER BY datasets DESC, portal;
Link
soql (portal VARCHAR, dataset_id VARCHAR, query VARCHAR, max_rows := BIGINT) 2 examples

Run a server-side SoQL query (aggregates, GROUP BY) on a Socrata dataset

Positional arguments
portal VARCHAR
The Socrata (Tyler Data & Insights) portal: a domain such as 'data.cityofnewyork.us', 'data.cityofchicago.org' or 'opendata.rdw.nl', or an https:// URL (a pasted dataset page URL is trimmed to the portal root).
dataset_id VARCHAR
The dataset's four-by-four id, as returned by datasets() and shown at the end of its page URL, e.g. 'erm2-nwe9'.
query VARCHAR
A SoQL query without FROM, e.g. 'SELECT borough, count(*) AS n WHERE created_date >= \'2024-01-01\' GROUP BY borough ORDER BY n DESC'.
Named arguments
max_rows := BIGINT
When the query has no LIMIT: fail if it returns more than this many rows (default 10,000). · default 10000
Returns columns
<text expression> VARCHAR
Text results and group keys.
<count / sum / avg / number expression> DECIMAL(28,10)
Numeric results.
<timestamp expression, e.g. date_trunc_ym(created_date)> TIMESTAMP
Floating timestamps.
<checkbox expression> BOOLEAN
Booleans.
<point / polygon expression> JSON
GeoJSON geometry.
borough VARCHAR
The borough (group key).
requests DECIMAL(28,10)
count(*) per borough.
primary_type VARCHAR
Crime type (group key).
arrests DECIMAL(28,10)
count(*) of arrests.
Returns columns · depends on the arguments
<text expression> VARCHAR
Text results and group keys.
<count / sum / avg / number expression> DECIMAL(28,10)
Numeric results.
<timestamp expression, e.g. date_trunc_ym(created_date)> TIMESTAMP
Floating timestamps.
<checkbox expression> BOOLEAN
Booleans.
<point / polygon expression> JSON
GeoJSON geometry.
borough VARCHAR
The borough (group key).
requests DECIMAL(28,10)
count(*) per borough.
primary_type VARCHAR
Crime type (group key).
arrests DECIMAL(28,10)
count(*) of arrests.
Examples (2)

NYC 311 requests per borough on 1 January 2024, counted by the portal

SELECT borough, requests::BIGINT AS requests
FROM socrata.main.soql('data.cityofnewyork.us', 'erm2-nwe9', 'SELECT borough, count(*) AS requests WHERE created_date >= ''2024-01-01T00:00:00'' AND created_date < ''2024-01-02T00:00:00'' GROUP BY borough ORDER BY borough')
ORDER BY borough;

The five crime types with the most arrests in Chicago on 1 January 2024

SELECT primary_type, arrests::BIGINT AS arrests
FROM socrata.main.soql('data.cityofchicago.org', 'ijzp-q8t2', 'SELECT primary_type, count(*) AS arrests WHERE arrest = true AND date >= ''2024-01-01T00:00:00'' AND date < ''2024-01-02T00:00:00'' GROUP BY primary_type ORDER BY arrests DESC, primary_type LIMIT 5')
ORDER BY arrests DESC, primary_type;
Link

Credentials

The secret type socrata declares, as reported by the worker itself.

socrata

How to get these credentials

Socrata app token (and optional base_url) for the portal hosts in the secret's SCOPE.

secret.sql
CREATE SECRET socrata (
    TYPE socrata,
    app_token '<APP_TOKEN>',  -- secret
    base_url  '<base_url>'
);
Key Type Required Description
app_token secret VARCHAR — Socrata app token, sent as X-App-Token; raises the anonymous throttling limit.
base_url VARCHAR — Send this host's requests to another base URL (a caching proxy, mirror or local fixture server) while results keep naming the real portal.

The worker doesn't mark which keys are required.

Create the secret in the same session, after attaching socrata — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

Datasets per category on the Dutch vehicle authority (RDW) portal, an EU portal

SELECT category, count(*) AS datasets
FROM socrata.main.datasets('opendata.rdw.nl')
GROUP BY category
ORDER BY datasets DESC, category

Uses datasets

Ten police use-of-force datasets from any US portal

SELECT portal, dataset_id, title
FROM socrata.main.search_datasets('police use of force', max_rows := 10)
ORDER BY portal, dataset_id

Uses search_datasets

Field names and types of NYC 311 service requests

SELECT field_name, data_type, duckdb_type
FROM socrata.main.dataset_columns('data.cityofnewyork.us', 'erm2-nwe9')
WHERE NOT is_system
ORDER BY position

Uses dataset_columns

NYC 311 complaint types in Brooklyn in the first ten minutes of 2024 (filters run on the portal)

SELECT complaint_type, count(*) AS requests
FROM socrata.main.dataset('data.cityofnewyork.us', 'erm2-nwe9')
WHERE created_date >= TIMESTAMP '2024-01-01 00:00:00' AND created_date < TIMESTAMP '2024-01-01 00:10:00' AND borough = 'BROOKLYN'
GROUP BY complaint_type
ORDER BY requests DESC, complaint_type

Uses dataset

NYC 311 requests per borough on 1 January 2024, counted by the portal

SELECT borough, requests::BIGINT AS requests
FROM socrata.main.soql('data.cityofnewyork.us', 'erm2-nwe9', 'SELECT borough, count(*) AS requests WHERE created_date >= ''2024-01-01T00:00:00'' AND created_date < ''2024-01-02T00:00:00'' GROUP BY borough ORDER BY borough')
ORDER BY borough

Uses soql

Quote a value containing an apostrophe for a SoQL condition

SELECT socrata.main.soql_quote('O''Brien') AS literal

Uses soql_quote

9 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using the Socrata worker, what is the dataset id (four-by-four) of the NYC '311 Service Requests from 2020 to Present' dataset on data.cityofnewyork.us?
  • How many Chicago Public Library branches are listed in the dataset x8fc-8rcq on data.cityofchicago.org?
  • What Socrata data type does the column created_date have in dataset erm2-nwe9 on data.cityofnewyork.us?
  • Search every US Socrata portal for 'police use of force' datasets (first 10 results). Which portal domains appear?
  • Escape the text 100%_done so it matches literally inside a SoQL like pattern.
  • Quote the text O'Brien as a SoQL string literal with the Socrata worker.

Socrata is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.