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 drug_and_alcohol_treatment_get_help_now_intake
table in this repository, by referencing it like:
"pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6:latest"."drug_and_alcohol_treatment_get_help_now_intake"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"callers_using_heroin", -- Number of calls resulting in intakes from callers concerned about their use of heroin. This data collection began in March 2018.
"male_callers", -- Number of calls resulting in intakes from callers identifying as male. This number is only available for the Commonwealth and not by county.
"callers_using_benzodiazepine", -- Number of calls resulting in intakes from callers concerned about their use of benzodiazepines. This data collection began in March 2018.
"callers_using_opiates", -- Number of calls resulting in intakes from callers concerned about their use of opiates. This data collection began in March 2018.
"callers_referred_to_social", -- Number of callers who were referred to social services. This number is only available for the Commonwealth and not by county.
"latitude_longitude", -- This includes a generic point of latitude for each county and a generic point for the state of PA to help with creating visuals such as maps. If the statewide total for PA should be shown on the map, this latitude provides the means to show the statewide total at the SE part of PA actually in Maryland, so that the statewide total can be shown on on the map without adding to the total within another county.
"longitude", -- This includes a generic point of longitude for each county and a generic point for the state of PA to help with creating visuals such as maps. If the statewide total for PA should be shown on the map, this longitude provides the means to show the statewide total at the SE part of PA actually in Maryland, so that the statewide total can be shown on on the map without adding to the total within another county.
"callers_using_cannabis", -- Number of calls resulting in intakes from callers concerned about their use of cannabis. This data collection began in March 2018.
"callers_referred_to_the", -- Number of callers who were referred to the emergency room. This type of referral is made when the caller is suicidal, or experiencing an alcohol/benzodiazepine withdrawal crisis. This number is only available for the Commonwealth and not by county.
"callers_referred_to_medication", -- Number of callers who were referred for Medical Assisted Treatment (MAT). This number is only available for the Commonwealth and not by county.
"callers_referred_to_outpatient", -- Number of callers who were referred to outpatient treatment. This number is only available for the Commonwealth and not by county.
"callers_referred_for", -- Number of callers who were referred for assessment. Typically, these individuals have private insurance, but may need additional county funding and are thus referred to their local Single County Authority (SCA). This number is only available for the Commonwealth and not by county.
"callers_receiving_at_least", -- Number of callers who were given at least one resource or referral over the telephone. This number is only available for the Commonwealth and not by county.
"callers_using_dissociative", -- Number of calls resulting in intakes from callers concerned about their use of Dissociative Anesthetic. Started collecting Dissociative Anesthetic January 14, 2019. Dissociative anesthesia is a form of anesthesia characterized by catalepsy, catatonia, analgesia, and amnesia. It does not necessarily involve loss of consciousness and thus does not always imply a state of general anesthesia.
"callers_using_suboxone", -- Number of calls resulting in intakes from callers concerned about their use of Suboxone. Started collecting Suboxone data July 2, 2018. SUBOXONE Film is a prescription medicine that contains the active ingredients buprenorphine and naloxone. It is used to treat adults who are dependent on (addicted to) opioids (either prescription or illegal).
"callers_using_methadone", -- Number of calls resulting in intakes from callers concerned about their use of methadone. This data collection began in March 2018.
"callers_using_narcotics_not", -- Number of calls resulting in intakes from callers concerned about their use of narcotics – not specified. This data collection began in March 2018.
"callers_using_stimulants", -- Number of calls resulting in intakes from callers concerned about their use of stimulants. This data collection began in March 2018.
"callers_using_alcohol", -- Number of calls resulting in intakes from callers concerned about their use of alcohol. This data collection began in March 2018.
"female_callers", -- Number of calls resulting in intakes from callers identifying as female. This number is only available for the Commonwealth and not by county.
"county_code", -- Number representing the County. This number should connect data to other files that have a county code.
"county_name", -- Geographic region in Pennsylvania representing where a caller lives. Pennsylvania has 67 counties. Commonwealth is listed as the State Total. Unknown is also listed.
"callers_using_hallucinogens", -- Number of calls resulting in intakes from callers concerned about their use of hallucinogens. This data collection began in March 2018.
":@computed_region_rayf_jjgk",
":@computed_region_r6rf_p9et",
"callers_referred_to_their", -- Number of callers who were referred to their local Single County Authority (SCA).The Pennsylvania Association of County Drug and Alcohol Administrators (PACDAA) is a professional association that represents the Single County Authorities (SCAs) across the commonwealth who receive state and federal dollars through contracts with the Department of Drug and Alcohol Programs (DDAP), to plan, coordinate, programmatically and fiscally manage and implement the delivery of drug and alcohol prevention, intervention, and treatment services at the local level. SCAs also receive funding for treatment services from the PA Department of Human Services (DHS), Office of Mental Health and Substance Abuse Services (OMHSAS). These services funded by DHS are primarily targeted to individuals in non-hospital residential care who are eligible for Medical assistance, or to a continuum of treatment services for those individuals no longer eligible as a result of welfare reforms. This number is only available for the Commonwealth and not by county.
"week_begin_date", -- Date (month/day/year) for each week’s beginning of data collection.
":@computed_region_amqz_jbr4",
"callers_referred_for_detox", -- Number of callers who were referred for detoxification or crisis stabilization. This number is only available for the Commonwealth and not by county.
"callers_referred_to_inpatient", -- Number of callers who were referred to inpatient residential treatment. This number is only available for the Commonwealth and not by county.
"county_fips_code", -- The FIPS county code is a five-digit Federal Information Processing Standard (FIPS) code (FIPS 6-4) which uniquely identifies counties and county equivalents in the United States, certain U.S. possessions, and certain freely associated states. 42000=Pennsylvania, 42001=Adams, 42003=Allegheny,…42133=York. This is the 5-digit Federal Information Processing Standard (FIPS) code that designate the State association. Each State has its own 2-digit number and each County within the state has its own 3-digit number which are combined into a 5-digit number to uniquely identify every US county. For more technical details : Federal Information Processing Standards Publications (FIPS PUBS) are issued by the National Institute of Standards and Technology (NIST) after approval by the Secretary of Commerce pursuant to Section 111 (d) of the Federal Property and Administrative Services Act of 1949 as amended by the Computer Security Act of 1987, Public Law 100-235. Federal Information Processing Standard (FIPS) 6-4, Counties and Equivalent Entities of the U.S., Its Possessions, and Associated Areas -- 90 Aug 31 , provides the names and codes that represent the counties and other entities treated as equivalent legal and/or statistical subdivisions of the 50 States, the District of Columbia, and the possessions and freely associated areas of the United States. Counties are considered to be the "first-order subdivisions" of each State and statistically equivalent entity, regardless of their local designations (county, parish, borough, etc.). Information gathered from census data - https://www.census.gov/library/reference/code-lists/ansi.html
"callers_referred_for_recovery", -- Number of callers who were referred for recovery support services. This number is only available for the Commonwealth and not by county.
"callers_referred_to_intensive", -- Number of callers who were referred to intensive outpatient treatment. This number is only available for the Commonwealth and not by county.
"callers_using_depressants", -- Number of calls resulting in intakes from callers concerned about their use of depressants. This data collection began in March 2018.
"geocoded_column", -- This includes a generic georeferenced point of Latitude and Longitude for each county and a generic point for the state of PA to help with creating visuals such as maps. If the statewide total for PA should be shown on the map, this centroid provides the means to show the statewide total at the SE part of PA actually in Maryland, so that the statewide total can be shown on on the map without adding to the total within another county.
"total_calls", -- Number of all Pennsylvania Get Help Now Hotline calls received during the week. This number is listed in the Commonwealth rows.
":@computed_region_d3gw_znnf",
":@computed_region_nmsq_hqvv",
"callers_receiving_information", -- Number of callers who were given information and/or resources, but were not referred to a treatment facility. This number is only available for the Commonwealth and not by county.
"total_intakes", -- Number of all Pennsylvania calls resulting in an intake during the week. An intake occurs when a person specifically wants a referral into treatment, and more demographic data about the caller is collected over the phone.. This number is listed for each county and the total is in the Commonwealth row.
"caller_receiving_warm_line" -- Number of calls resulting in a direct telephone connection from the hotline staff to a treatment facility. Some callers may receive more than one warm-line connection if the first facility cannot accommodate them. This number is only available for the Commonwealth and not by county.
FROM
"pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6:latest"."drug_and_alcohol_treatment_get_help_now_intake"
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 pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6
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 pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6: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 pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6
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 pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6:latest
This will download all the objects for the latest
tag of pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6
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 pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6: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 pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6: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, pa-gov/drug-and-alcohol-treatment-get-help-now-intake-7mj7-q4j6
is just another Postgres schema.