# 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 `work_status_in_the_past_12_months_20072011`

table in this repository, by referencing it like:

`"bronx-lehman-cuny-edu/work-status-in-the-past-12-months-20072011-73x4-nns8:latest"."work_status_in_the_past_12_months_20072011"`

or in a full query, like:

```
SELECT
":id", -- Socrata column ID
"male_estimate_usual_hours_worked_usually_worked_15_to_34_ho_000",
"total_margin_of_error_percent_imputed_weeks_worked_in_the_past_",
"male_margin_of_error_usual_hours_worked_did_not_work",
"total_margin_of_error_mean_usual_hours_worked_for_workers",
"male_margin_of_error_mean_usual_hours_worked_for_workers",
"total_margin_of_error_percent_imputed_work_status_in_the_past_1",
"zipcode",
"point_y",
"total_estimate_population_16_to_64_years",
"total_margin_of_error_population_16_to_64_years",
"male_margin_of_error_population_16_to_64_years",
"female_estimate_population_16_to_64_years",
"total_estimate_weeks_worked_worked_50_to_52_weeks",
"total_margin_of_error_weeks_worked_worked_50_to_52_weeks",
"male_estimate_weeks_worked_worked_50_to_52_weeks",
"male_margin_of_error_weeks_worked_worked_50_to_52_weeks",
"female_estimate_weeks_worked_worked_50_to_52_weeks",
"female_margin_of_error_weeks_worked_worked_50_to_52_weeks",
"total_estimate_weeks_worked_worked_40_to_49_weeks",
"total_margin_of_error_weeks_worked_worked_40_to_49_weeks",
"female_estimate_weeks_worked_worked_40_to_49_weeks",
"female_margin_of_error_weeks_worked_worked_40_to_49_weeks",
"total_estimate_weeks_worked_worked_27_to_39_weeks",
"total_margin_of_error_weeks_worked_worked_27_to_39_weeks",
"male_estimate_weeks_worked_worked_27_to_39_weeks",
"male_margin_of_error_weeks_worked_worked_27_to_39_weeks",
"female_estimate_weeks_worked_worked_27_to_39_weeks",
"female_margin_of_error_weeks_worked_worked_27_to_39_weeks",
"total_estimate_weeks_worked_worked_14_to_26_weeks",
"total_margin_of_error_weeks_worked_worked_14_to_26_weeks",
"male_estimate_weeks_worked_worked_14_to_26_weeks",
"female_estimate_weeks_worked_worked_14_to_26_weeks",
"female_margin_of_error_weeks_worked_worked_14_to_26_weeks",
"total_estimate_weeks_worked_worked_1_to_13_weeks",
"total_margin_of_error_weeks_worked_worked_1_to_13_weeks",
"male_estimate_weeks_worked_worked_1_to_13_weeks",
"male_margin_of_error_weeks_worked_worked_1_to_13_weeks",
"female_estimate_weeks_worked_worked_1_to_13_weeks",
"female_margin_of_error_weeks_worked_worked_1_to_13_weeks",
"total_estimate_weeks_worked_did_not_work",
"total_margin_of_error_weeks_worked_did_not_work",
"male_estimate_weeks_worked_did_not_work",
"male_margin_of_error_weeks_worked_did_not_work",
"female_estimate_weeks_worked_did_not_work",
"female_margin_of_error_weeks_worked_did_not_work",
"total_estimate_usual_hours_worked_usually_worked_35_or_more_000",
"total_margin_of_error_usual_hours_worked_usually_worked_35__000",
"male_estimate_usual_hours_worked_usually_worked_35_or_more__000",
"male_margin_of_error_usual_hours_worked_usually_worked_35_o_000",
"female_estimate_usual_hours_worked_usually_worked_35_or_mor_000",
"female_margin_of_error_usual_hours_worked_usually_worked_35_000",
"total_estimate_usual_hours_worked_usually_worked_35_or_more_001",
"total_margin_of_error_usual_hours_worked_usually_worked_35__001",
"male_estimate_usual_hours_worked_usually_worked_35_or_more__001",
"male_margin_of_error_usual_hours_worked_usually_worked_35_o_001",
"female_estimate_usual_hours_worked_usually_worked_35_or_mor_001",
"female_margin_of_error_usual_hours_worked_usually_worked_35_001",
"total_estimate_usual_hours_worked_usually_worked_35_or_more_002",
"total_margin_of_error_usual_hours_worked_usually_worked_35__002",
"male_estimate_usual_hours_worked_usually_worked_35_or_more__002",
"male_margin_of_error_usual_hours_worked_usually_worked_35_o_002",
"female_estimate_usual_hours_worked_usually_worked_35_or_mor_002",
"female_margin_of_error_usual_hours_worked_usually_worked_35_002",
"total_estimate_usual_hours_worked_usually_worked_15_to_34_h_000",
"total_margin_of_error_usual_hours_worked_usually_worked_15__000",
"male_estimate_usual_hours_worked_usually_worked_15_to_34_ho_001",
"female_estimate_usual_hours_worked_usually_worked_15_to_34__000",
"female_margin_of_error_usual_hours_worked_usually_worked_15_000",
"total_estimate_usual_hours_worked_usually_worked_15_to_34_h_001",
"male_margin_of_error_usual_hours_worked_usually_worked_15_t_000",
"female_estimate_usual_hours_worked_usually_worked_15_to_34__001",
"female_margin_of_error_usual_hours_worked_usually_worked_15_001",
"total_estimate_usual_hours_worked_usually_worked_15_to_34_h_002",
"total_margin_of_error_usual_hours_worked_usually_worked_15__001",
"male_estimate_usual_hours_worked_usually_worked_15_to_34_ho_002",
"male_margin_of_error_usual_hours_worked_usually_worked_15_t_001",
"female_estimate_usual_hours_worked_usually_worked_15_to_34__002",
"female_margin_of_error_usual_hours_worked_usually_worked_15_002",
"total_estimate_usual_hours_worked_usually_worked_1_to_14_ho_000",
"male_estimate_usual_hours_worked_usually_worked_1_to_14_hou_000",
"female_estimate_usual_hours_worked_usually_worked_1_to_14_h_000",
"male_estimate_usual_hours_worked_usually_worked_1_to_14_hou_001",
"female_estimate_usual_hours_worked_usually_worked_1_to_14_h_001",
"female_margin_of_error_usual_hours_worked_usually_worked_1__000",
"total_margin_of_error_usual_hours_worked_usually_worked_1_t_000",
"male_estimate_usual_hours_worked_usually_worked_1_to_14_hou_002",
"male_margin_of_error_usual_hours_worked_usually_worked_1_to_000",
"female_estimate_usual_hours_worked_usually_worked_1_to_14_h_002",
"female_margin_of_error_usual_hours_worked_usually_worked_1__001",
"total_estimate_usual_hours_worked_did_not_work",
"total_margin_of_error_usual_hours_worked_did_not_work",
"male_estimate_usual_hours_worked_did_not_work",
"female_estimate_usual_hours_worked_did_not_work",
"female_margin_of_error_usual_hours_worked_did_not_work",
"total_estimate_mean_usual_hours_worked_for_workers",
"male_estimate_mean_usual_hours_worked_for_workers",
"female_estimate_mean_usual_hours_worked_for_workers",
"female_margin_of_error_mean_usual_hours_worked_for_workers",
"total_estimate_percent_imputed_work_status_in_the_past_12_month",
"male_estimate_percent_imputed_work_status_in_the_past_12_months",
"male_margin_of_error_percent_imputed_work_status_in_the_past_12",
"female_estimate_percent_imputed_work_status_in_the_past_12_mont",
"female_margin_of_error_percent_imputed_work_status_in_the_past_",
"total_estimate_percent_imputed_hours_worked_per_week_in_the_pas",
"total_margin_of_error_percent_imputed_hours_worked_per_week_in_",
"male_estimate_percent_imputed_hours_worked_per_week_in_the_past",
"male_margin_of_error_percent_imputed_hours_worked_per_week_in_t",
"female_estimate_percent_imputed_hours_worked_per_week_in_the_pa",
"female_margin_of_error_percent_imputed_hours_worked_per_week_in",
"total_estimate_percent_imputed_weeks_worked_in_the_past_12_mont",
"male_estimate_percent_imputed_weeks_worked_in_the_past_12_month",
"male_margin_of_error_percent_imputed_weeks_worked_in_the_past_1",
"female_estimate_percent_imputed_weeks_worked_in_the_past_12_mon",
"female_margin_of_error_percent_imputed_weeks_worked_in_the_past",
":@computed_region_tx27_6f7w",
":@computed_region_s8vt_86fu",
":@computed_region_itb6_w327",
":@computed_region_23ia_pkqc",
"point_x",
"point_x_address",
"male_estimate_population_16_to_64_years",
"female_margin_of_error_population_16_to_64_years",
"male_estimate_weeks_worked_worked_40_to_49_weeks",
"male_margin_of_error_weeks_worked_worked_40_to_49_weeks",
"male_margin_of_error_weeks_worked_worked_14_to_26_weeks",
"male_margin_of_error_usual_hours_worked_usually_worked_15_t_002",
"total_margin_of_error_usual_hours_worked_usually_worked_15__002",
"total_margin_of_error_usual_hours_worked_usually_worked_1_t_001",
"male_margin_of_error_usual_hours_worked_usually_worked_1_to_001",
"female_margin_of_error_usual_hours_worked_usually_worked_1__002",
"total_estimate_usual_hours_worked_usually_worked_1_to_14_ho_001",
"total_margin_of_error_usual_hours_worked_usually_worked_1_t_002",
"male_margin_of_error_usual_hours_worked_usually_worked_1_to_002",
"total_estimate_usual_hours_worked_usually_worked_1_to_14_ho_002",
"point_x_city",
"point_x_state",
"point_x_zip"
FROM
"bronx-lehman-cuny-edu/work-status-in-the-past-12-months-20072011-73x4-nns8:latest"."work_status_in_the_past_12_months_20072011"
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 `bronx-lehman-cuny-edu/work-status-in-the-past-12-months-20072011-73x4-nns8`

with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at bronx.lehman.cuny.edu. When you query`bronx-lehman-cuny-edu/work-status-in-the-past-12-months-20072011-73x4-nns8: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 bronx.lehman.cuny.edu, 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 \
"bronx-lehman-cuny-edu/work-status-in-the-past-12-months-20072011-73x4-nns8" \
--handler-options '{
"domain": "bronx.lehman.cuny.edu",
"tables": {
"work_status_in_the_past_12_months_20072011": "73x4-nns8"
}
}'
```

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, `bronx-lehman-cuny-edu/work-status-in-the-past-12-months-20072011-73x4-nns8`

is just another Postgres schema.