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 ovcf_sgr_ejecucin_de_gastos
table in this repository, by referencing it like:
"datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54:latest"."ovcf_sgr_ejecucin_de_gastos"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"codigo_entidad", -- Código que identifica a la Entidad del Estado a la que corresponde el presupuesto
"cod_cpc", -- refiere al código de la cuenta de producto contable. Este código es un identificador único que se asigna a cada cuenta contable dentro del Plan Único de Cuentas para Colombia (PUC).
"nom_politica_publica", -- Política Pública bajo la que se hace la adquisición
"ambito_codigo", -- Identificador del nivel de gobierno al que corresponde la información reportada, código alfanumérico que representa el nivel de gobierno al que se asocia la información fiscal.
"cod_politica_publica", -- Este campo contiene un código único que vincula las transacciones financieras a iniciativas o programas gubernamentales específicos.
"nom_programatico_mga", -- El campo debe contener una descripción clara y concisa del programa o proyecto específico al que se asocian los ingresos o gastos reportados. Esta descripción debe ser lo suficientemente detallada para permitir la correcta clasificación y análisis de la información financiera.
"nombre_cuenta", -- Descripción de la cuenta contable correspondiente al registro
"nom_terceros", -- Nombre de las terceras entidades involucradas en las transacciones financieras que se reportan.
"nom_fuentes_financiacion", -- Fuente de Financiación para la Adquisicion
"cuenta", -- Identificador de la cuenta correspondiente al registro
"cod_tipo_recurso", -- Código Tipo de Recurso a partir del cual se hace la adquisición del bien o servicio asociado al gasto, esto refiere al Origen del gasto
"cod_terceros", -- Identificador único para entidades de terceros que interactúan con compañías que participan en transacciones asociadas al gasto reportado.
"nombre_entidad", -- Nombre de la Entidad del Estado a la que corresponde el presupuesto
"nom_situacion_de_fondos", -- Representa el estado o posición financiera de una entidad o proyecto en particular con respecto a sus fondos disponibles y su utilización. Proporciona una instantánea de la salud financiera de la entidad y la asignación de recursos.
"nom_cpc", -- Refiere al Item de la cuenta de producto contable. Este código es un identificador único que se asigna a cada cuenta contable dentro del Plan Único de Cuentas para Colombia (PUC).
"nom_sector", -- Sector de la Economía al que corresponde la adquisición asociada al gasto
"nom_tipo_recursos", -- Tipo de Recurso a partir del cual se hace la adquisición del bien o servicio asociado al gasto
"bpin", -- Código del Banco de Proyectos asociado a la adquisicion a la que corresponde el gasto
"periodo", -- Período de reporte por parte de la Entidad, conformado por el año y el mes
"pagos", -- Se utiliza para registrar los pagos realizados a empresas o terceros
"obligaciones", -- “Obligaciones” financieras asociadas con un proyecto o una actividad generadora de recursos. Abarca los diversos compromisos y pasivos financieros en los que ha incurrido o se espera que incurra el proyecto o la actividad.
"compromisos", -- Se refiere al presupuesto total comprometido para un proyecto o actividad específica. Representa los recursos financieros que han sido asignados y comprometidos para la ejecución del proyecto o actividad.
"cod_situacion_de_fondos", -- Este campo proporciona una representación codificada de la situación financiera general de la entidad, indicando si tiene superávit o déficit de fondos.
"cod_fuentes_financiacion", -- Sirve como identificador único del origen de los fondos utilizados para financiar las actividades o transacciones que generan los ingresos y gastos reportados en la información fiscal.
"cod_sector", -- Corresponde a un sector económico específico.
"cod_programatico_mga" -- Identificador único para códigos programáticos específicos dentro de la Metodología General Ajustada (MGA), una metodología estandarizada para formular y evaluar proyectos de inversión pública en Colombia.
FROM
"datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54:latest"."ovcf_sgr_ejecucin_de_gastos"
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 datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54
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 datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54: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 datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54
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 datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54:latest
This will download all the objects for the latest
tag of datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54
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 datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54: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 datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54: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, datos-gov-co/ovcf-sgr-ejecucin-de-gastos-qkv4-ek54
is just another Postgres schema.