datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d
Loading...

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

"datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d:latest"."baseline_study_of_food_for_peace_title_ii"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "g25a_12", -- G25A What crops did you store
    "other_methods", -- Other methods other crops
    "g17_5", -- G17 Where did you purchase drugs or medicine
    "rice_storage", -- Storage method Rice
    "g18_4", -- G18 Did you use any of the following natural resources managment practices or techniques
    "sustainable_livestock_cat", -- Farmers who used at least 2 sustainable livestock practices in the past 12 months
    "soil_plow", -- Soil preparation by ox plow
    "watershed", -- Management of watershed or reforestation
    "manage_plantation", -- Management of forest plantation
    "animal_drugs", -- Purchased drugs medicines to give to animals
    "g25a_5", -- G25A What crops did you store
    "shelters", -- Animal shelters
    "water_catchment", -- Construction of water catchments
    "g18_2", -- G18 Did you use any of the following natural resources managment practices or techniques
    "g19", -- G19 REFER TO G04 IS ANSWER YES
    "soil_conservation", -- Soil conservation on hillsides
    "credit", -- Obtained an agricultural credit in the last 12 months
    "silo", -- Silo other crops
    "g17_3", -- G17 Where did you purchase drugs or medicine
    "drugs_veterinarian", -- Purchased drugs or medicine from a veterinarian or community health worker
    "tillage", -- Tillage of land
    "g25b_c3", -- G25B What was the main method that you used to store
    "veterinary", -- Use the services of community animal health workers
    "g25b_c6", -- G25B What was the main method that you used to store
    "sorghum_storage", -- Storage method Sorghum
    "processing", -- Drying or processing produce
    "savings", -- Saved money in the last 12 months
    "g24", -- G24 Did you store rice
    "intercropping", -- Intercropping
    "g18_3", -- G18 Did you use any of the following natural resources managment practices or techniques
    "g18_7", -- G18 Did you use any of the following natural resources managment practices or techniques
    "g18_6", -- G18 Did you use any of the following natural resources managment practices or techniques
    "storage", -- Stored sorghum maize legumes rice or other crops
    "livestock_no", -- No livestock
    "animal_feeds", -- Homemade animal feeds made of locally available products
    "bulk_transport", -- Bulk transporting of inputs produce or animals
    "nrm_none", -- No activities
    "g18_1", -- G18 Did you use any of the following natural resources managment practices or techniques
    "vaccination", -- Vaccination
    "g25a_3", -- G25A What crops did you store
    "fmwt", -- Farmer sampling weight
    "soil_hand", -- Soil preparation by hand
    "value_chain_any", -- Farmers who practiced at least two of the value chain activities promoted by the project in the past 12 months
    "g25a_4", -- G25A What crops did you store
    "g25a_9", -- G25A What crops did you store
    "fertilizer", -- Applying fertilizer
    "natural_regeneration", -- Management of natural regeneration
    "g25a_8", -- G25A What crops did you store
    "g22", -- G22 Did you store maize
    "seeds_rows", -- Planting seeds in rows
    "maize_storage", -- Storage method Maize
    "g25a_6", -- G25A What crops did you store
    "granary", -- Granary other crops
    "g25a_14", -- G25A What crops did you store
    "g18_9", -- G18 Did you use any of the following natural resources managment practices or techniques
    "sustainable_agriculture_cat", -- Farmers who used at least 3 sustainable agriculture practices in the past 12 months
    "legumes_storage", -- Storage method Legumes
    "g25a_7", -- G25A What crops did you store
    "crops_other", -- Other crop practices
    "sorting", -- Sorting produce
    "broadcasting", -- Broadcasting seed
    "c25b_c4", -- G25B What was the main method that you used to store
    "grading", -- Grading produce
    "valuechain_none", -- No activities
    "soil_tractor", -- Soil preparation by tractor
    "crop_rotation", -- Crop rotation
    "g16_s9_10", -- G16 S9 Did you use any of these practices for species 1 9 sheep
    "sustainable_agriculture", -- Number of sustainable agriculture practices in the past 12 months
    "strata", -- Strata
    "sustainable_livestock", -- Number of sustainable livestock practices in the past 12 months
    "g17_1", -- G17 Where did you purchase drugs or medicine
    "g18_8", -- G18 Did you use any of the following natural resources managment practices or techniques
    "cluster", -- Cluster
    "forest_products", -- Collecting products from forest plants such as gum arabic
    "member_id", -- Household member ID for merging with other modules
    "sustainable_ag", -- Number of sustainable agriculture crop practices and or technologies in the past 12 months
    "g25b_c2", -- G25B What was the main method that you used to store
    "trading", -- Trading or marketing wholesale retail or export
    "valuechain_other", -- Other activities
    "g23", -- G23 Did you store legumes
    "livestock", -- Have animals that raise care for and make decisions about
    "g21", -- G21 Did you store sorghum
    "g26", -- G26 Did you support the bolus scheme
    "cereal_bank", -- Cereal bank other crops
    "g25a_11", -- G25A What crops did you store
    "insurance", -- Had agricultural insurance in the last 12 months
    "g25a_10", -- G25A What crops did you store
    "purchase_inputs", -- Purchase inputs
    "g18_5", -- G18 Did you use any of the following natural resources managment practices or techniques
    "value_chain_cat", -- Farmers who practiced at least two of the value chain activities promoted by the project in the past 12 months
    "g25", -- G25 Did you store any other crops
    "pvo", -- PVO
    "sustainable_nrm", -- Number of sustainable NRM practices in the past 12 months
    "g25b_c5", -- G25B What was the main method that you used to store
    "g16_s9_9", -- G16 S9 Did you use any of these practices for species 1 9 sheep
    "kraals", -- Kraals
    "g18_10", -- G18 Did you use any of the following natural resources managment practices or techniques
    "g25a_15", -- G25A What crops did you store
    "sustainable_ag_cat", -- Farmers who used at least 2 sustainable agriculture crop practices and or technologies in the past 12 months
    "improved_storage", -- Farmers who used improved storage practices in the past 12 months
    "g17_2", -- G17 Where did you purchase drugs or medicine
    "g25a_2", -- G25A What crops did you store
    "g24a", -- G24A What was the main method that you used to store rice
    "agroforestry", -- Agro forestry or cultivation of fruit trees
    "crops", -- Planted any crops within the last 12 months
    "g25a_13", -- G25A What crops did you store
    "financial_services", -- Farmers who used any financial services in the past 12 months
    "id",
    "g22a", -- G22A What was the main method that you used to store maize
    "g20", -- G20 During the past 12 months did you store any crops from your plots
    "g17_4", -- G17 Where did you purchase drugs or medicine
    "g21a", -- G21A What was the main method that you used to store sorghum
    "deworming", -- Deworming
    "value_chain_all_cat", -- Farmers who practiced all the value chain activities promoted by the project in the past 12 months
    "g25a_1", -- G25A What crops did you store
    "sustainable_nrm_cat", -- Farmers who used at least 1 sustainable NRM practices in the past 12 months
    "crops_no", -- No crops
    "n_crops", -- Number of crops produced
    "livestock_none", -- No activities
    "g25b_c1", -- G25B What was the main method that you used to store
    "crops_none", -- No activities
    "g23a" -- G23A What was the main method that you used to store legumes
FROM
    "datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d:latest"."baseline_study_of_food_for_peace_title_ii"
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 datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d 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 datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d: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 datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d

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 datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d:latest

This will download all the objects for the latest tag of datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d 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 datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d: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 datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d: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, datahub-usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d is just another Postgres schema.

Related Documentation:

Loading...