Query the Data Delivery Network

Query the DDN

The 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_2019 table in this repository, by referencing it like:

"ny-gov/patient-characteristics-survey-pcs-2019-urn3-ezfe:latest"."patient_characteristics_survey_pcs_2019"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "cannabis_recreational_use", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "received_smoking_counseling", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "opioid_12m_service", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "ssdi_cash_assistance", -- ‘Yes’, ‘No’, or ‘Unknown’
    "medicaid_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’
    "child_health_plus_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’
    "autism_spectrum", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "hearing_impairment", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "stroke", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "endocrine_condition", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "cancer", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "heart_attack", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "hyperlipidemia", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "kidney_disease", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "medicare_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’
    "neurological_condition", -- ‘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
    "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
    "received_smoking_medication", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "serious_mental_illness", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "ssi_cash_assistance", -- ‘Yes’, ‘No’, or ‘Unknown’
    "race", -- ‘Black Only’, ‘Multi-Racial’, ‘Other’ (includes American Indian/Alaska Native Only, Asian Only, Native Hawaii/Other Pac Islander Only, and Other Race Only), ‘White Only’ or ‘Unknown Race’.
    "intellectual_disability", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "speech_impairment", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "survey_year", -- Dates for 2019 Patient Characteristic Survey are between 10/21/2019 and 10/27/2019.
    "sexual_orientation", -- ‘Bisexual’, ‘Lesbian or Gay’, ‘Straight or Heterosexual’, ‘Other’, ‘Client Did Not Answer’, or ‘Unknown’.
    "hispanic_ethnicity", -- ‘Yes’, ‘No, Not Hispanic/Latino’, or ‘Unknown’.
    "living_situation", -- ‘Private Residence’, ‘Institutional Setting’, ’Other Living Situation’, or ‘Unknown’. Go to http://bi.omh.ny.gov/bridges/definitions#5 to view OMH’s residential program definitions
    "preferred_language", -- ‘English’, ‘Spanish’, ’Indo-European’, ‘Asian and Pacific Island’, ‘Afro-Asiatic’ ‘All Other Languages’, or ‘Unknown’.
    "number_of_hours_worked_each", -- ‘01-14 Hours’, ‘15-34’, ‘35 Hours or More’, ‘Not Applicable’, or ‘Unknown Employment Hours’.
    "special_education_services", -- ‘Yes’, ‘No’, ‘Not Applicable’, ‘Unknown’.
    "mental_illness", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "other_developmental_disability", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "drug_substance_disorder", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "mobility_impairment_disorder", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "visual_impairment", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "high_blood_pressure", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "diabetes", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "joint_disease", -- ‘Yes’, ‘No’, or ‘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
    "cannabis_medicinal_use", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "alcohol_12m_service", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "principal_diagnosis_class", -- ‘Mental Illness’, ‘Not MI- Developmental Disorders’, ‘Not MI- Organic Mental Disorder’, ‘Not MI- Other’, ‘Substance-related and Addictive Disorders’, or ‘Unknown’.
    "additional_diagnosis_class", -- ‘Mental Illness’, ‘Not MI- Developmental Disorders’, ‘Not MI- Organic Mental Disorder’, ‘Not MI- Other’, ‘Substance-related and Addictive Disorders’, ’No Additional Diagnosis’, or ‘Unknown’.
    "medicaid_managed_insurance", -- ‘Yes’, ‘No’, ‘Not Applicable’, ‘Unknown’.
    "private_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’
    "other_insurance", -- ‘Yes’, ‘No’, or ‘Unknown’
    "criminal_justice_status", -- ‘Yes’, ‘No’, or ‘Unknown’
    "program_category", --  ‘Emergency’, ‘Inpatient’, ‘Outpatient’, ‘Residential’, or ‘Support’. Go to http://bi.omh.ny.gov/bridges/definitions to view OMH’s program category definitions.
    "region_served", -- Represents region where client received service.  Regions include ‘Central NY’, ‘Hudson River’, ‘Long Island’, ‘New York City’, ‘Western’. The following counties comprise the OMH regions: 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.
    "age_group", -- 'Child’, ‘Adult’, ‘Unknown’
    "household_composition", -- ‘Lives Alone’, ’Cohabitates with Others’, ‘Not Applicable’, or ‘Unknown’. 
    "religious_preference", -- ‘I belong to a formal religious group’, ‘I do not have a formal religion, nor am I a spiritual person’, ‘I consider myself spiritual, but not religious’, or ‘Data not available’
    "employment_status", -- ‘Employed’, ‘Non-paid/Volunteer’, ‘Not In Labor Force: Unemployed and not looking for work’, ‘Unemployed, looking for work’, or ‘Unknown Employment Status’.
    "education_status", -- ‘No Formal Education’, ‘Pre-K to Fifth Grade’, ‘Middle School to High School’, ‘Some College’, ‘College or Graduate Degree’, ‘Other’, or ‘Unknown’.
    "opioid_related_disorder", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "obesity", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "other_cardiac", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "other_chronic_med_condition", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "drug_substance_12m_service", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "veterans_disability_benefits", -- ‘Yes’, ‘No’, or ‘Unknown’
    "veterans_cash_assistance", -- ‘Yes’, ‘No’, or ‘Unknown’
    "three_digit_residence_zip", -- Three digit residential zip code. Three digit zip code 777 indicates the client lived other State in the United States or Other Country, Three digit zip code 888 indicates the client was homeless at the time of the survey, and three digit zip code 999 indicates the residential zip code is unknown.
    "public_assistance_cash_program", -- ‘Yes’, ‘No’, or ‘Unknown’
    "alcohol_related_disorder", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "medicaid_and_medicare", -- ‘Yes’, ‘No’, or ‘Unknown’
    "alzheimer_or_dementia", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "smokes", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "other_cash_benefits", -- ‘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
    "sex", -- ‘Female’, ‘Male’, ‘Unknown’.
    "pulmonary_asthma", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "transgender", -- ‘No, Not Transgender’, ‘Yes, Transgender’, ‘Client Did Not Answer’, or ‘Unknown’.  
    "veteran_status", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "liver_disease", -- ‘Yes’, ‘No’, or ‘Unknown’.
    "traumatic_brain_injury" -- ‘Yes’, ‘No’, or ‘Unknown’.
FROM
    "ny-gov/patient-characteristics-survey-pcs-2019-urn3-ezfe:latest"."patient_characteristics_survey_pcs_2019"
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-2019-urn3-ezfe with SQL in under 60 seconds.

Query Your Local Engine

Install Splitgraph Locally
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; sgrcan 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 cloneand sgr checkout.

Cloning Data

Because ny-gov/patient-characteristics-survey-pcs-2019-urn3-ezfe: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-2019-urn3-ezfe

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-2019-urn3-ezfe:latest

This will download all the objects for the latest tag of ny-gov/patient-characteristics-survey-pcs-2019-urn3-ezfe 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-2019-urn3-ezfe: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-2019-urn3-ezfe: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-2019-urn3-ezfe is just another Postgres schema.

Related Documentation:

Loading...