Queries using SODA | Socrata

Queries using SODA Overview

The Socrata APIs provide rich query functionality through a query language we call the “Socrata Query Language” or “SoQL”. As its name might suggest, it borrows heavily from Structured Query Language (SQL)

API Endpoints

(http://en.wikipedia.org/wiki/Sql), used by many relational database systems. Its paradigms should be familiar to


most developers who have previously worked with SQL, and are easy to learn for those who are new to it.

Row Identifiers (/docs/rowidentifiers.html) RESTful Verbs (/docs/verbs.html) Application Tokens (/docs/app-tokens.html) Authentication (/docs/authentication.html) Response Codes & Headers (/docs/response-codes.html) System Fields (/docs/system-fields.html) CORS & JSONP (/docs/cors-and-jsonp.html)

Filtering & Querying Simple Filters (/docs/filtering.html) SoQL Queries (/docs/queries/) Paging Through Data (/docs/paging.html) SoQL Function Listing (/docs/functions/)

Data Formats (/docs/formats/) JSON (/docs/formats/json.html) GeoJSON

SoQL Clauses SoQL statements are broken into “parameters” similar to clauses in SQL statements. Each clause can be expressed either directly as a URL parameter or as a SoQL statement. If a parameter is not specified, then the default is used. Click each parameter name for more details: Parameter



$select The set of columns to be returned, All columns, equivalent to $select=* (/docs/queries/select.html) similar to a SELECT in SQL $where Filters the rows to be returned, No filter (/docs/queries/where.html) similar to WHERE $order Column to order results on, similar to Unspecified order (/docs/queries/order.html) ORDER BY in SQL $group Column to group results on, similar to No grouping (/docs/queries/group.html) GROUP BY in SQL $having Filters the rows that result from an No filter (/docs/queries/having.html)aggregation, similar to HAVING $limit 1000 (2.0 endpoints: maximum of 50,000; Maximum number of results to return 2.1: unlimited » (/docs/endpoints.html)) (/docs/queries/limit.html) $offset Offset count into the results to start 0 (/docs/queries/offset.html) at, used for paging Performs a full text search for a $q (/docs/queries/q.html) No search value. $query A full SoQL query string, all as one N/A (/docs/queries/query.html) parameter $$bom Prepends a UTF-8 Byte Order Mark false (/docs/queries/bom.html) to the beginning of CSV output


Note that for equality comparisons, the $where clause can be replaced with using the column name as the query parameter. See filtering (/docs/filtering.html) for more details. These parameters can then be directly added to the API endpoint. For example, here is how you would query the USGS Earthquakes datasets for quakes of greater than 3.0 on the Richter scale:


https://soda.demo.socrata.com/resource/4tka-6guv.json?$where=magnitude > 3.0




In examples, we will leave the parameters as is, but it is best to URL Encode

RDF-XML (/docs/formats/rdf-

(http://en.wikipedia.org/wiki/Url_encode) your parameters to ensure they are parsed correctly.


Datatypes (/docs/datatypes/) Checkbox (/docs/datatypes/checkbox.html) Double (/docs/datatypes/double.html) Floating Timestamp (/docs/datatypes/floating_timestamp.html)

Line (/docs/datatypes/line.html) Location (/docs/datatypes/location.html) Money (/docs/datatypes/money.html) MultiLine (/docs/datatypes/multiline.html) MultiPoint (/docs/datatypes/multipoint.html) MultiPolygon (/docs/datatypes/multipolygon.html) Number (/docs/datatypes/number.html) Point (/docs/datatypes/point.html) Polygon (/docs/datatypes/polygon.html) Text (/docs/datatypes/text.html)

Other APIs Discovery (http://docs.socratadiscovery.apiary.io/) Open Performance (http://docs.openperformance.apiary.io/) OData (/odata/)

(http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US) Licensed by Socrata (http://socrata.com) under CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US). Learn how you can contribute! (/contributing.html)


Queries using SODA | Socrata

Queries using SODA Overview The Socrata APIs provide rich query functionality through a query language we call the “Socrata Query Language” or “SoQL”...

44KB Sizes 3 Downloads 16 Views

Recommend Documents

No documents