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 protocol. 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 nycha_resident_data_book_summary
table in this repository, by referencing it like:
"cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3:latest"."nycha_resident_data_book_summary"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"total_families_on_welfare_and_hoh_elderly", -- A welfare family with head of household 62 years old and over.
"residents_4_to_5",
"total_families_on_welfare_as_percent_of_families", -- Number of welfare families divided by total number of families,
"total_male_headed_single_parent_grandparent_with_minors", -- A family having a Male Single Parent or a Grandparent plus at least a child under 18 years old.
"all_average_gross_rent", -- Mean monthly rent paid by the household.
"total_families_1_or_more_employed_as_percent_of_families",
"residents_14_to_17",
"residents_21_to_49",
"total_minors_under_18", -- Population under 18 years old
"residents_6_to_9",
"residents_10_to_13",
"program", -- Funding program of NYCHA development
"total_male_headed_families", -- Family with a male head of household
"residents_18_to_20",
"total_elderly_population", -- Population age 62 or over
"total_families", -- Total number of households for all NYCHA developments.
"residents_under_4",
"residents_62_plus",
"total_single_parent_grandparent_families_on_welfare", -- A family defined as one parent family with minor under 18 and with the head of household and/or family member receiving any type of public assistance regardless of receiving other type of income source. Other type of income includes employment, own business, social security benefits, survivors insurance, supplemental security income, benefits from public & non-public funds and assets, unemployment insurance, federal wages, housing authority wages, military wages, pension, child support and alimony.
"total_single_parent_grandparent_with_minors_as_of_families", -- Number of total single parent/grandparent families on welfare divided by total number of families.
"total_families_on_welfare", -- Number of families with head and/or family member receiving any type of public assistance regardless of receiving other type of income source. Other type of income includes employment, own business, social security benefits, survivors insurance, supplemental security income, benefits from public & non-public funds and assets, unemployment insurance, federal wages, housing authority wages, military wages, pension, child support and alimony.
"total_elderly_single_person_families", -- Single head of household age 62 or over
"total_minors_as_percent_of_population", -- Population under 18 years old divided by total population
"total_families_2nd_adult_employed",
"total_female_headed_families", -- Family with a female head of household
"total_families_1_or_more_employed", -- A family where at least the head of household and/or family member receives income from employment and/or own business and/or unemployment insurance and/or federal wages and/or housing authority wages and/or military wages regardless of receiving any other type of income.
"all_families_average_years_in_public_housing",
"total_female_headed_hoh_62_years_and_over", -- Total Number of households with a female head of household age 62 or over
"total_fixed_income_families_as_percent_of_families", -- Total number of families on fixed income divided by the total number of families
"total_62_years_and_over_as_percent_of_population", -- Population age 62 and over divided by total population
"total_population", -- Total population.
"average_minors_per_family", -- Ratio of population under 18 years old to total number of families
"total_hoh_62_years_and_over", -- Total number of households with a head of household age 62 or over
"total_hoh_62_years_and_over_as_percent_of_families", -- Total number of households with a head of household age 62 or over divided by total number of families
"total_fixed_income_families",
"total_male_headed_hoh_62_years_and_over", -- Total Number of households with a male head of household age 62 or over
"total_single_parent_grandparent_families_with_minors", -- A family having a Single Parent or a Grandparent plus at least a child under 18 years old.
"all_average_total_gross_income", -- Mean of the gross grand total household income which is the sum of the values of all income sources for the head of household and all other members of the household. Income sources includes employment, own business, public assistance, social security benefits, survivors insurance, supplemental security income, benefits from public & non-public funds and assets, unemployment insurance, federal wages, housing authority wages, military wages, pension, child support and alimony.
"average_family_size", -- Ratio of total population to total number of families
"residents_50_to_61",
"statecity_section8_flag", -- Aggregated level for total, public, and section 8 transition households
"total_families_on_full_welfare", -- Number of families with head and/or family member receiving any type of public assistance and no other type of income for the household.
"total_female_headed_single_parent_grandparent_with_minors" -- A family having a Female Single Parent or a Grandparent plus at least a child under 18 years old.
FROM
"cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3:latest"."nycha_resident_data_book_summary"
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 cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3
with SQL in under 60 seconds.
Query Your Local Engine
bash -c "$(curl -sL https://github.com/splitgraph/splitgraph/releases/latest/download/install.sh)"
Read the installation docs.
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, 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 (like this repository), where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr clone
and sgr checkout
.
Cloning Data
Because cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3:latest
is a Splitgraph Image, you can clone the data from Spltgraph Cloud to your local engine, where you can query it like any other Postgres database, using any of your existing tools.
First, install Splitgraph if you haven't already.
Clone the metadata with sgr clone
This will be quick, and does not download the actual data.
sgr clone cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3
Checkout the data
Once you've cloned the data, you need to "checkout" the tag that you want. For example, to checkout the latest
tag:
sgr checkout cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3:latest
This will download all the objects for the latest
tag of cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3
and load them into the Splitgraph Engine. Depending on your connection speed and the size of the data, you will need to wait for the checkout to complete. Once it's complete, you will be able to query the data like you would any other Postgres database.
Alternatively, use "layered checkout" to avoid downloading all the data
The data in cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3:latest
is 0 bytes. If this is too big to download all at once, or perhaps you only need to query a subset of it, you can use a layered checkout.:
sgr checkout --layered cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3:latest
This will not download all the data, but it will create a schema comprised of foreign tables, that you can query as you would any other data. Splitgraph will lazily download the required objects as you query the data. In some cases, this might be faster or more efficient than a regular checkout.
Read the layered querying documentation to learn about when and why you might want to use layered queries.
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, cityofnewyork-us/nycha-resident-data-book-summary-5r5y-pvs3
is just another Postgres schema.