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 american_community_survey_2018_2022_estimates_by
table in this repository, by referencing it like:
"cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz:latest"."american_community_survey_2018_2022_estimates_by"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"female", -- Female population as proportion of neighborhood population.
"geocoded_column",
"latitude",
"pop_in_group_quarters", -- Proportion of population residing in group quarters. Group Quarters are places where people live or stay, in a group living arrangement that is owned or managed by an entity or organization providing housing and/or services for the residents. College/University Dormitories are considered Group Quarters as are correctional facilities, juvenile facilities, nursing facilities, other health care facilities, military group quarters and other non- institutional facilities (homeless shelters, rehab facilities).
"nonfamily_hhs_roommate", -- Proportion of neighborhood households composed of roommates, including unmarried partners who do not reside with a relative.
"family_w_o_children_hhs", -- Proportion of neighborhood households composed of families without related children under 18. A family consists of two or more people (one of whom is the householder) related by birth, marriage, or adoption residing in the same housing unit.
"family_w_children_hhs", -- Share of total households that are families with children under 18. A family consists of two or more people (one of whom is the householder) related by birth, marriage, or adoption residing in the same housing unit.
"number_of_families", -- Number of family households in neighborhood. A family household consists of two or more persons who are related by ancestry, marriage or adoption.
"male", -- Male population as proportion of neighborhood population.
"land_area_in_square_miles",
"land_area_in_acres",
"total_population",
"longitude",
"nonfamily_hhs_single_persons", -- Proportion of neighborhood households composed of one person.
"population_as_of_city_total",
"persons_per_acre",
"land_area_as_of_city_total",
"hispanic", -- Proportion of neighborhood population who identifies as Hispanic.
"non_hispanic", -- Proportion of neighborhood population who no identify as Hispanic.
"age_5_yrs",
"age_18_yrs",
"age_65_yrs",
"age_18_to_24_yrs",
":@computed_region_guic_hr4a",
"neighborhood",
"age_5_to_17_yrs",
"age_25_to_34_yrs",
"age_35_to_44_yrs",
"age_45_to_54_yrs",
"area",
"age_55_to_64_yrs",
"population_in_households", -- Total population living in Households. A household consists of one or people who reside in a housing unit. A household may consist of a single person, two or more unrelated people, or a family.
"population_in_households_1", -- Percentage of the total population living in households. Any residents who not reside in a household reside in group quarters, which includes college dormitories.
"persons_per_household", -- Average household size for the neighborhood. A household consists of one or people who reside in a housing unit. A household may consist of a single person, two or more unrelated people, or a family.
":@computed_region_rffn_qbt6",
"american_indian_pct", -- Proportion of the neighborhood population who selected either American Indian or Alaska Native as their only racial category.
"asian_pac_is", -- Proportion of the neighborhood population who selected either Asian or Pacific Islander as their only racial category.
"black", -- Proportion of the neighborhood population who selected Black as their only racial category.
"white", -- Proportion of the neighborhood population who selected White as their only racial category.
"other_races_population", -- Proportion of the neighborhood population who selected only Race/Other.
"two_or_more_races_pct", -- Proportion of the neighborhood population who selected two or more races.
":@computed_region_swkg_bavi",
":@computed_region_e4yd_rwk4",
":@computed_region_v7jj_366k",
"households" -- Total number of households residing in the neighborhood. A household consists of all people who occupy a housing unit regardless of relationship. A household may consist of a person living alone, multiple unrelated individuals, or families living together.
FROM
"cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz:latest"."american_community_survey_2018_2022_estimates_by"
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 cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz
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 cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz: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 cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz
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 cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz:latest
This will download all the objects for the latest
tag of cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz
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 cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz: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 cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz: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, cambridgema-gov/american-community-survey-2018-2022-estimates-by-jabj-v7kz
is just another Postgres schema.