# Query the Data Delivery Network

Query the DDNThe easiest way to query any data on Splitgraph is via the "Data Delivery Network" (DDN). The DDN is a single endpoint that speaks the PostgreSQL wire procotol. Any Splitgraph user can connect to it at `data.splitgraph.com:5432`

and query any version of over 40,000 datasets that are hosted or proxied by Splitgraph.

For example, you can query the `horseshoe_crab_spawning_survey`

table in this repository, by referencing it like:

`"delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg:latest"."horseshoe_crab_spawning_survey"`

or in a full query, like:

```
SELECT
":id", -- Socrata column ID
"baywide_male_spawning_activity", -- The mean of the total number of male crabs per total area available for the spawning survey on all surveyed beaches.
"nj_female_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of female horseshoe crab spawning activity in New Jersey
"nj_female_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of female horseshoe crab spawning activity in New Jersey
"nj_male_spawning_activity", -- The mean of the total number of male crabs per total area available for the spawning survey on all NJ surveyed beaches
"de_female_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of female horseshoe crab spawning activity in Delaware
"de_male_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of female horseshoe crab spawning activity in Delaware
"de_male_spawning_activity", -- The mean of the total number of male crabs per total area available for the spawning survey on all DE surveyed beaches
"baywide_female_cv", -- Coefficient of variation - Unitless description of the amount of variation relative to the mean Index of Spawning Activity (ISA), expressed as a percentage for females
"baywide_female_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of female horseshoe crab spawning activity
"baywide_female_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of female horseshoe crab spawning activity
"baywide_female_spawning_activity", -- Index of female horseshoe crab spawning activity - mean number of female crabs per square meter per night for Delaware and New Jersey beaches
"baywide_male_cv", -- Coefficient of variation - Unitless description of the amount of variation relative to the mean Index of Spawning Activity (ISA), expressed as a percentage for males
"baywide_male_sd", -- Standard Deviation - Statistical variation of Index of Spawning Activity (ISA) values for males
"baywide_male_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of male horseshoe crab spawning activity
"baywide_male_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of male horseshoe crab spawning activity
"total_beaches_surveyed", -- Number of beaches on which the standardized form of the spawning survey was conducted baywide
"baywide_spawning_activitylunar_period_4", -- The mean of the total number of female crabs per total area available for the spawning survey on all surveyed beaches. The second moon phase (new or full) in June around which surveying occurs - 2 days before, day of, 2 days after (typically the last period of surveying).
"baywide_spawning_activitylunar_period_3", -- The mean of the total number of female crabs per total area available for the spawning survey on all surveyed beaches. The first moon phase (new or full) in June around which surveying occurs - 2 days before, day of, 2 days after.
"baywide_spawning_activitylunar_period_2", -- The mean of the total number of female crabs per total area available for the spawning survey on all surveyed beaches. The second moon phase (new or full) in May around which surveying occurs - 2 days before, day of, 2 days after.
"baywide_spawning_activity_lunar_period_1", -- The mean of the total number of female crabs per total area available for the spawning survey on all surveyed beaches. The first moon phase (new or full) in May around which surveying begins - 2 days before, day of, 2 days after.
"avg_daily_water_temp_in_may_c", -- Average of daily water temperatures recorded at the National Ocean Service station at Lewes, DE (Station Identification Number 8557380) during the month of May in °Celsius
"nj_female_spawning_in_may", -- Proportion of females recorded during May of a given survey year on New Jersey Beaches
"year", -- Year of survey
"numbermalesperfemale", -- The number of males observed in a given spawning season per female observed during that same season.
"baywide_female_sd", -- Standard Deviation - Statistical variation of Index of Spawning Activity (ISA) values for females
"de_beaches_surveyed", -- Number of beaches on which the standardized form of the spawning survey was conducted in Delaware
"de_female_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of female horseshoe crab spawning activity in Delaware
"nj_male_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of male horseshoe crab spawning activity in New Jersey
"nj_male_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of male horseshoe crab spawning activity in New Jersey
"de_male_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of male horseshoe crab spawning activity in Delaware
"nj_beaches_surveyed", -- Number of beaches on which the standardized form of the spawning survey was conducted in New Jersey
"de_female_spawning_activity", -- The mean of the total number of female crabs per total area available for the spawning survey on all DE surveyed beaches
"de_female_spawning_in_may", -- Proportion of females recorded during May of a given survey year on Delaware beaches
"nj_female_spawning_activity" -- The mean of the total number of female crabs per total area available for the spawning survey on all NJ surveyed beaches
FROM
"delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg:latest"."horseshoe_crab_spawning_survey"
LIMIT 100;
```

Connecting to the DDN is easy. All you need is an existing SQL client that can connect to Postgres. As long as you have a SQL client ready, you'll be able to query `delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg`

with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.delaware.gov. When you query`delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg:latest`

on the DDN, we "mount" the repository using the `socrata`

mount handler. The mount handler proxies your SQL query to the upstream data source, translating it from SQL to the relevant language (in this case SoQL).

We also cache query responses on the DDN, but we run the DDN on multiple nodes so a `CACHE_HIT`

is only guaranteed for subsequent queries that land on the same node.

# Query Your Local Engine

`bash -c "$(curl -sL https://github.com/splitgraph/splitgraph/releases/latest/download/install.sh)"`

Splitgraph Cloud is built around Splitgraph Core (GitHub), which includes a local Splitgraph Engine packaged as a Docker image. Splitgraph Cloud is basically a scaled-up version of that local Engine. When you query the Data Delivery Network or the REST API, we mount the relevant datasets in an Engine on our servers and execute your query on it.

It's possible to run this engine locally. You'll need a Mac, Windows or Linux system to install `sgr`

, and a Docker installation to run the engine. You don't need to know how to actually *use* Docker; `sgr`

can manage the image, container and volume for you.

There are a few ways to ingest data into the local engine.

For **external repositories** (like this repository), the Splitgraph Engine can "mount" upstream data sources by using `sgr mount`

. This feature is built around Postgres Foreign Data Wrappers (FDW). You can write custom "mount handlers" for any upstream data source. For an example, we blogged about making a custom mount handler for HackerNews stories.

For **hosted datasets**, where the author has pushed **Splitgraph Images** to the repository, you can "clone" and/or "checkout" the data using `sgr clone`

and `sgr checkout`

.

## Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.delaware.gov, and Splitgraph indexes it. This means it is not an actual Splitgraph image, so you cannot use `sgr clone`

to get the data. Instead, you can use the `socrata`

adapter with the `sgr mount`

command. Then, if you want, you can import the data and turn it into a Splitgraph image that others can clone.

First, install Splitgraph if you haven't already.

### Mount the table with `sgr mount`

```
sgr mount socrata \
"delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg" \
--handler-options '{
"domain": "data.delaware.gov",
"tables": {
"horseshoe_crab_spawning_survey": "cqsj-dfgg"
}
}'
```

That's it! Now you can query the data in the mounted table like any other Postgres table.

### Query the data with your existing tools

Once you've loaded the data into your local Splitgraph engine, you can query it with any of your existing tools. As far as they're concerned, `delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg`

is just another Postgres schema.