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 patient_characteristics_survey_pcs_2013
table in this repository, by referencing it like:
"ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5:latest"."patient_characteristics_survey_pcs_2013"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"employment_status", -- ‘Employed’, ‘Non-paid work position (volunteer)’, ‘Unemployed, looking for work’, ‘Not In Labor Force: unemployed and not looking for work’, or ‘Unknown Employment Status’.
"work_hours", -- ‘1-14 Hours’, ‘15-34’, ‘35 Hours or More’, ‘Not Applicable’, or ‘Unknown Employment Hours’.
"high_blood_pressure", -- ‘Yes’, ‘No’, or ‘Unknown’.
"primary_language", -- ‘English’, ‘Spanish’, ’Indo-European’, ‘Asian and Pacific Island’, ‘Afro-Asiatic’ ‘All Other Languages’, or ‘Unknown’.
"endocrine_condition", -- ‘Yes’, ‘No’, or ‘Unknown’.
"alzheimer_or_dementia", -- ‘Yes’, ‘No’, or ‘Unknown’
"living_situation", -- ‘Private Residence’, ‘Institutional Setting’, ‘Other Living Situation’, or ‘Unknown’. OMH definitions may be found at http://bi.omh.ny.gov/bridges/definitions#5
"no_insurance", -- ‘Yes’ – Indicates individual DOES NOT have any health insurance; ‘No’ – Indicates individual has at least one type of health insurance; ‘Unknown’ – Indicates that it is not known whether individual has health insurance
"smokes", -- ‘Yes’, ‘No’, or ‘Unknown’.
"no_chronic_med_condition", -- ‘Yes’ – Indicates individual DOES NOT have a chronic medical condition; ‘No’ – Indicates individual has at least one chronic medical condition; ‘Unknown’ – Indicates that it is not known whether individual has a chronic medical condition
"medicare_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"sex", -- ‘Female’, ‘Male’, ‘Unknown’.
"veteran_status", -- ‘Yes’, ‘No’, or ‘Unknown’.
"intellectual_disability", -- ‘Yes’, ‘No’, or ‘Unknown’.
"criminal_justice_status", -- ‘Adjudicated Juvenile Delinquent or Offender’, ‘Alternative to Incarceration (ATI) status, Mental Health Court, Court Diversion’, ‘Article 10-Sex Offender Management & Treatment (SOMTA)’, ‘County/City Jail, Court Detention or Police lockup, Prisoner (including CPL 730 and CL 508 referrals)’, ‘Criminal Procedure Law (CPL) 330.20’, ‘NYS Dept. of Correctional Services Prisoner’ ‘Other criminal justice status’, ‘Parolee (adults)’, ‘PINS (Person in Need of Supervision)’, ‘Probationer (adults)’, ‘None’, ‘Unknown whether or not client has a criminal justice or juvenile justice status’.
"stroke", -- ‘Yes’, ‘No’, or ‘Unknown’.
"hearing_visual_impairment", -- ‘Yes’, ‘No’, or ‘Unknown’.
"special_educational_services", -- ‘Yes’, ‘No’, ‘NA’, ‘Unknown’.
"private_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"principal_diagnosis_class", -- ‘Mental Illness’, ‘Mental Retardation/Dev. Disorder’, ‘Organic Mental Disorder’, ‘Physical Disorder’, ‘Substance‐related Disorder’, or ‘Unknown’.
"other_cash_benefits", -- ‘Yes’, ‘No’, or ‘Unknown’.
"medicaid_and_medicare_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"unknown_insurance_coverage", -- ‘Yes’ – Indicates that it is not known whether individual has health insurance; ‘No’ – Indicates individual has at least one type of health insurance
"medicaid_managed_insurance", -- ‘Yes’, ‘No’, ‘NA’, ‘Unknown’.
"other_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"medicaid_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"age_group", -- ‘Child, ‘Adult’, or ‘Unknown’
"three_digit_residential_zip_code", -- Three digit residential zip code. Three digit zip code 888 indicates Homeless and three digit zip code 999 indicates Unknown.
"unknown_chronic_med_condition", -- ‘Yes’ – Indicates that it is not known whether individual has a chronic medical condition; ‘No’ – Indicates individual has at least one chronic medical condition
"survey_year", -- Dates for 2013 Patient Characteristic Survey are between 10/21/2013 and 10/27/2013.
"mobility_impairment_disorder", -- ‘Yes’, ‘No’, or ‘Unknown’.
"drug_substance_related_disorder", -- ‘Yes’, ‘No’, or ‘Unknown’.
"receives_smoking_counseling", -- ‘Yes’, ‘No’, or ‘Unknown’.
"other_developmental_disabilities", -- ‘Yes’, ‘No’, or ‘Unknown’.
"serious_mental_illness", -- ‘Yes’ or ‘No’.
"ssi_cash_assistance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"pulmonary_asthma", -- ‘Yes’, ‘No’, or ‘Unknown’.
"other_cardiac", -- ‘Yes’, ‘No’, or ‘Unknown’.
"diabetes", -- ‘Yes’, ‘No’, or ‘Unknown’.
"hispanic_ethnicity", -- ‘Yes’, ‘No, Not Hispanic/Latino’, or ‘Unknown’.
"ssdi_cash_assistance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"public_assistance_cash_program", -- ‘Yes’, ‘No’, or ‘Unknown’.
"heart_attack", -- ‘Yes’, ‘No’, or ‘Unknown’.
"sexual_orientation", -- ‘Bisexual’, ‘Lesbian, Gay, or Homosexual’, ‘Straight or Heterosexual’, ‘Other’, or ‘Unknown’.
"obesity", -- ‘Yes’, ‘No’, or ‘Unknown’.
"hyperlipidemia", -- ‘Yes’, ‘No’, or ‘Unknown’.
"alcohol_related_disorder", -- ‘Yes’, ‘No’, or ‘Unknown’.
"family_health_plus_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"child_health_plus_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"mental_illness", -- ‘Yes’, ‘No’, or ‘Unknown’.
"kidney_disease", -- ‘Yes’, ‘No’, or ‘Unknown’.
"autism_spectrum", -- ‘Yes’, ‘No’, or ‘Unknown’.
"region_served", -- ‘Central NY’, ‘Hudson River’, ‘Long Island’, ‘New York City’, ‘Unknown’, or ‘Western’. ‘Unknown’ is designated to maintain confidentiality. The following counties comprise the OMH region definitions: Central New York--Broome, Cayuga, Chenango, Clinton, Cortland, Delaware, Essex, Franklin, Fulton, Hamilton, Herkimer, Jefferson, Lewis, Madison, Montgomery, Oneida, Onondaga, Oswego, Otsego, Saint Lawrence; Hudson River--Albany, Columbia, Dutchess, Greene, Orange, Putnam, Rensselaer, Rockland, Saratoga, Schenectady, Schoharie, Sullivan, Ulster, Warren, Washington, Westchester; Long Island--Nassau, Suffolk; New York City--Bronx, Kings, New York, Queens, Richmond; Western New York--Allegany, Cattaraugus, Chautauqua, Chemung, Erie, Genesee, Livingston, Monroe, Niagara, Ontario, Orleans, Schuyler, Seneca, Steuben, Tioga, Tompkins, Wayne, Wyoming, Yates
"educational_status", -- ‘No Formal Education’, ‘Pre-K to Fifth Grade’, ‘Middle School to High School’, College or Graduate Degree’, ‘Some College’, ‘Other’, or ‘Unknown’.
"veterans_cash_assistance", -- ‘Yes’, ‘No’, or ‘Unknown’.
"household_composition", -- ‘Lives alone’, ‘Cohabitates with Others’, ‘Not Applicable’, or ‘Unknown’.
"transgender", -- ‘Yes, Transgender’, ‘No, Not Transgender’ or ‘Unknown’.
"additional_diagnosis_class", -- ‘Mental Illness’, ‘Mental Retardation/Dev. Disorder’, ‘Organic Mental Disorder’, ‘Physical Disorder’, ‘Substance‐related Disorder’, or ‘Unknown’.
"receives_smoking_medication", -- ‘Yes’, ‘No’, or ‘Unknown’.
"race", -- ‘Black Only’, ‘Multi‐Racial’, ‘Other’ (includes ‘American Indian/Alaska Native Only’, ‘Asian Only’, ‘Native Hawaii/Other Pacific Islander Only’, and ‘Other Race Only’), ‘White Only’ or ‘Unknown Race’.
"neurological_condition", -- ‘Yes’, ‘No’, or ‘Unknown’.
"cancer", -- ‘Yes’, ‘No’, or ‘Unknown’.
"veterans_disability_benefits", -- ‘Yes’, ‘No’, or ‘Unknown’.
"liver_disease", -- ‘Yes’, ‘No’, or ‘Unknown’.
"traumatic_brain_injury", -- ‘Yes’, ‘No’, or ‘Unknown’.
"joint_disease", -- ‘Yes’, ‘No’, or ‘Unknown’.
"program_category" -- ‘Emergency’, ‘Inpatient’, ‘Outpatient’, ‘Residential’, or ‘Support’. Definitions available at http://bi.omh.ny.gov/bridges/definitions.
FROM
"ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5:latest"."patient_characteristics_survey_pcs_2013"
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 ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5
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 ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5: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 ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5
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 ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5:latest
This will download all the objects for the latest
tag of ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5
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 ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5: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 ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5: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, ny-gov/patient-characteristics-survey-pcs-2013-ck8p-rrj5
is just another Postgres schema.