{"id":20486257,"url":"https://github.com/undp-data/pgsql","last_synced_at":"2026-01-30T14:17:17.978Z","repository":{"id":216849464,"uuid":"560344390","full_name":"UNDP-Data/pgsql","owner":"UNDP-Data","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-12T17:16:28.000Z","size":3120,"stargazers_count":2,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-14T16:04:12.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UNDP-Data.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-11-01T09:32:03.000Z","updated_at":"2023-06-27T10:39:43.000Z","dependencies_parsed_at":"2024-01-13T08:03:52.680Z","dependency_job_id":"60d934a6-5bc5-419b-9277-8ccfb719aacb","html_url":"https://github.com/UNDP-Data/pgsql","commit_stats":null,"previous_names":["undp-data/pgsql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/UNDP-Data/pgsql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UNDP-Data%2Fpgsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UNDP-Data%2Fpgsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UNDP-Data%2Fpgsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UNDP-Data%2Fpgsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UNDP-Data","download_url":"https://codeload.github.com/UNDP-Data/pgsql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UNDP-Data%2Fpgsql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28913974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T12:13:43.263Z","status":"ssl_error","status_checked_at":"2026-01-30T12:13:22.389Z","response_time":66,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T16:35:52.385Z","updated_at":"2026-01-30T14:17:17.960Z","avatar_url":"https://github.com/UNDP-Data.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"This repo contains geo-analytical PostgreSQL functions used by UNDP GeoHub.\nas well as python tools to help with development/testing. The tools leverage asyncpg\nlibrary to connect to Postgres and mapbox_vector_tile library to parse/view the results\n\n# Drivers\nThere are multiple options to connect to Postgres from python [psycopg2/3](https://www.psycopg.org/)\nor [asyncpg](https://github.com/MagicStack/asyncpg). While the former is probably well know the \nlater is preferred because it is:\n\n- async\n- binary\n- faster\n- fully integrated with Postgres machinery (logging)\n\nThe disadvantage is the users has to adhere to the python [async](https://docs.python.org/3/library/asyncio.html) machinery.\n\n# Usage\n\n## clone\n```commandline\ngit clone https://github.com/UNDP-Data/pgsql.git\ncd psql\n```\n\n- setup POSTGRES_DSN variable through .env file (see [.env.example](.env.example))\n- run the [example](./src/geohubsql/example.py)\n\nIn principle, the sql functions need to be located inside [sql](./src/geohubsql/sql) folder.\nOnce a function is created here it can be executed using [run_sql_func](https://github.com/UNDP-Data/pgsql/blob/main/src/geohubsql/util.py#L144)\n\n\n```python\nimport asyncio\nfrom dotenv import dotenv_values\nfrom geohubsql import util\nevars = dotenv_values('../../.env')\ndsn = evars['POSTGRES_DSN']\nbytes = asyncio.run(util.run_sql_func(sql_func_name='filter_layer.sql',\n                                      dsn=dsn,\n                                      filter_table='admin.admin0',\n                                      filter_column='iso3cd',\n                                      filter_value='C')\n                    )\nutil.dump_mvt(bytes)\n\nINFO:geohubsql.util:0, {'iso3cd': 'COD'}\nINFO:geohubsql.util:0, {'iso3cd': 'CHL'}\nINFO:geohubsql.util:0, {'iso3cd': 'CAF'}\nINFO:geohubsql.util:0, {'iso3cd': 'COG'}\nINFO:geohubsql.util:0, {'iso3cd': 'CZE'}\nINFO:geohubsql.util:0, {'iso3cd': 'CYP'}\nINFO:geohubsql.util:0, {'iso3cd': 'CPV'}\nINFO:geohubsql.util:0, {'iso3cd': 'CYM'}\nINFO:geohubsql.util:0, {'iso3cd': 'CAN'}\nINFO:geohubsql.util:0, {'iso3cd': 'CUB'}\nINFO:geohubsql.util:0, {'iso3cd': 'CHE'}\nINFO:geohubsql.util:0, {'iso3cd': 'CHN'}\nINFO:geohubsql.util:0, {'iso3cd': 'CRI'}\nINFO:geohubsql.util:0, {'iso3cd': 'CMR'}\nINFO:geohubsql.util:0, {'iso3cd': 'CUW'}\nINFO:geohubsql.util:0, {'iso3cd': 'COK'}\nINFO:geohubsql.util:0, {'iso3cd': 'CXR'}\nINFO:geohubsql.util:0, {'iso3cd': 'COL'}\nINFO:geohubsql.util:0, {'iso3cd': 'COM'}\nINFO:geohubsql.util:0, {'iso3cd': 'CIV'}\n```\n\nThe `run_sql_func` function is able to connect automatically to Postgres, can intercept the Postgres\nlogs from the SQL function, parses the argumnets used by the **sql_func_name** argument and \nmakes sure none of the mandatory args of the SQL function **sql_func_name** are omitted.\n\nAll of these happens under the hood using  as decorator  and a series of utility functions\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fundp-data%2Fpgsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fundp-data%2Fpgsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fundp-data%2Fpgsql/lists"}