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 census_combined_statistical_area_in_colorado_2010
table in this repository, by referencing it like:
"colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i:latest"."census_combined_statistical_area_in_colorado_2010"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"the_geom", -- GeoJSON field describing the boundaries of the area
"name10", -- The name of the designated area (eg Block Group 3)
"namelsad10", -- The full name of the designated area (eg Census Tract 9638, Gunnison County, Colorado)
"csa", -- The ID value for the designated area (only value is 216)
"geocsa", -- The ID value made up of the state and the ID above (eg 08216)
"arealand", -- The amount of land in the designated area, in ft2.
"areawatr", -- The amount of water in the designated area, in ft2.
"intptlat", -- The center of the latitude of the designated area.
"intptlon", -- The center of the longitude of the designated area.
"pop2010", -- The number of people living in the designated area as of 2010.
"hispanic", -- Estimate for the Hispanic Population
"pct_hisp", -- The percentage of people self designated as hispanic (not white).
"white_nh", -- Estimate for the White, Non-Hispanic Population
"pct_white", -- The percentage of people self designated as white (not hispanic).
"black_nh", -- Estimate for the Black, Non-Hispanic Population
"pct_black", -- The percentage of people self designated as black (not hispanic)
"amerind_nh", -- The number of people self designated as native american (not hispanic).
"pct_amind", -- The percentage of people self designated as native american (not hispanic).
"asian_nh", -- Estimate for the Asian, Non-Hispanic Population
"pct_asian", -- The percentage of people self designated as asian
"hawpac_nh", -- The number of people self designated as hawaiian.
"pct_hawpi", -- The percentage of people self designated as hawaiian.
"other_nh", -- Estimate for the population of those identifying with any other race (Non-Hispanic)
"pct_other", -- The percentage of people self designated as none of the above.
"mult_nh", -- The number of people self designated as multi-ethnic
"pct_mult", -- The percentage of people self designated as multi-ethnic
"male", -- Estimate for the total male population
"pct_male", -- The percentage of people self designated as males
"female", -- Estimate for the total female population
"pct_fem", -- The percentage of people self designated as females
"age65plus", -- Estimate for the total population 65 years of age or older
"pct_65plus", -- The percentage of people age 65 and older
"ageunder18", -- The number of people younger than 18
"pct_u18", -- The percentage of people younger than 18
"ageunder10", -- The number of people younger than 10
"pct_u10", -- The percentage of people younger than 10
"med_age", -- Median age of the population for the area
"med_male", -- The median age of all self designated males in the designated area
"med_female", -- The median age of all self designated females in the designated area
"households", -- Estimate for the total number of household
"family_hh", -- The number of households self designated as family
"husb_wife", -- The number of family households designated as having a husband and wife.
"oth_family", -- The number of family households designated as not having a husband and wife.
"non_fam", -- The number of households self designated as not family
"hh_alone", -- The number of households where the resident is living alone
"avg_hh", -- The average number of people in a household
"hh_w_nonr", -- The number of households with non-relatives living together
"hh_n_nonr", -- The number of households with no non-relatives living together
"avg_fam", -- The average number of people in a family
"gq_pop", -- The number in group quarters
"gq_inst", -- The number in group quarters living in an institutional facility
"gq_correc", -- The number in group quarters living in an adult correctional facility
"gq_juvenl", -- The number in group quarters living in a juvenile correctional facility
"gq_nurs", -- The number living in nursing homes
"gq_ot_inst", -- The number living in an institutional facility not mentioned above
"gq_noninst", -- The number in group quarters living in a non-institutional facility
"gq_college", -- The number living in college housing
"gq_miltry", -- The number living in military quarters
"gq_o_noni", -- The number living in any non-institutional facility not mentioned above
"housing_un", -- Estimated total number of housing units
"occupied", -- The number of houses occupied in the designated area
"pct_occ", -- The percentage of houses occupied in the designated area
"vacant", -- The number of houses vacant in the designated area
"pct_vac", -- The percentage of houses vacant in the designated area
"owner", -- The number of houses that are owned by their occupants in the designated area
"pct_own", -- The percentage of houses that are owned by their occupants in the designated area
"renter", -- The number of houses that are rented by their occupants in the designated area
"pct_rent", -- The percentage of houses that are rented by their occupants in the designated area
"v_forrent", -- The number of vacant houses for rent in the designated area
"v_r_notocc", -- The number of vacant, rented, but not occupied housing units
"v_forsale", -- The number of vacant housing units for sale in the designated area
"v_s_notocc", -- The number of vacant, sold, but not occupied housing units
"v_seasonal", -- The number of vacant housing units that are for seasonal use
"v_migrant", -- The number of vacant housing units for migrant workers
"v_other" -- The number of vacant housing units that are vacant for any reason not mentioned above
FROM
"colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i:latest"."census_combined_statistical_area_in_colorado_2010"
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 colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i
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 colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i: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 colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i
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 colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i:latest
This will download all the objects for the latest
tag of colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i
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 colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i: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 colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i: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, colorado-gov/census-combined-statistical-area-in-colorado-2010-5733-dk6i
is just another Postgres schema.