{"id":19718955,"url":"https://github.com/legolasvzla/pgplsql-useful-examples","last_synced_at":"2025-08-11T17:08:00.413Z","repository":{"id":111952603,"uuid":"196113098","full_name":"LegolasVzla/pgplsql-useful-examples","owner":"LegolasVzla","description":"Pgplsql useful scripts examples","archived":false,"fork":false,"pushed_at":"2020-02-20T15:07:55.000Z","size":421,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-27T23:14:35.416Z","etag":null,"topics":["database-migrations","etl","geopy","plpgsql","plpgsql-scripts","plpython","postgis","postgresql","tree-structure"],"latest_commit_sha":null,"homepage":null,"language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LegolasVzla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-10T02:06:58.000Z","updated_at":"2021-04-22T01:18:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b03b541-27b2-4cd9-b433-bfc961661694","html_url":"https://github.com/LegolasVzla/pgplsql-useful-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LegolasVzla/pgplsql-useful-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fpgplsql-useful-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fpgplsql-useful-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fpgplsql-useful-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fpgplsql-useful-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LegolasVzla","download_url":"https://codeload.github.com/LegolasVzla/pgplsql-useful-examples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fpgplsql-useful-examples/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269922906,"owners_count":24496999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["database-migrations","etl","geopy","plpgsql","plpgsql-scripts","plpython","postgis","postgresql","tree-structure"],"created_at":"2024-11-11T23:02:51.706Z","updated_at":"2025-08-11T17:08:00.398Z","avatar_url":"https://github.com/LegolasVzla.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgplsql-useful-examples\nPgplsql useful scripts examples\n\nThis a repository for Pgplsql useful scripts examples.\n\n## ETL's\n\nSome examples of a data migration between 2 PostgreSQL databases, related with a Aeronautic sector project. Some useful things that you can found there are:\n\n- Use of the Cursors\n\n- Cleaning of data\n\n- And more things...\n\n## Tree queries\n\n* Use:\n\nGive permissions to execute_all.sh file:\n\n\tchmod +x execute_all.sh\n\nLogin as a postgres user:\n\n\tsudo -i -u postgres\n\nMove to the path where your clone this repository and then go to tree-queries folder:\n\n\tcd tree-queries/\n\nFinally, execute the execute_all.sh file:\n\n\t./execute_all.sh\n\n* Structure:\n\nFiles are contained inside of the temporal_schema folder, with the below structure:\n\na) schema -\u003e functions: generating queries with tree json format.\n\nb) schema -\u003e tables: examples tables.\n\nc) schema -\u003e data: mock data.\n\n## Tree postgis queries\n\n* Use:\n\nGive permissions to execute_all.sh file:\n\n\tchmod +x execute_all.sh\n\nLogin as a postgres user:\n\n\tsudo -i -u postgres\n\nMove to the path where your clone this repository and then go to tree-postgis-queries folder:\n\n\tcd tree-postgis-queries/\n\nFinally, execute the execute_all.sh file:\n\n\t./execute_all.sh\n\n* Structure:\n\nFiles are contained inside of the temporal_schema folder, with the below structure:\n\na) schema -\u003e functions: generating queries with tree json format:\n\n- udf_spots_nearby_current_user_position: get the first 5 nearest records disregard how far the are away from the current location.\n\n- udf_images_get.sql: get the images list related with a spot.\n\n- udf_categories_get.sql: get the categories list related with a spot.\n\n- udf_like_actions_get.sql: get the likes list related with a spot.\n\n- udf_comments_get.sql: get the comments related with a spot.\n\n- udf_commented_liked_get.sql: get the likes related with a comment of a spot.\n\n- udf_users_tagged_get.sql: get the users tagged related with a spot.\n\n- udf_tags_get.sql: get the tags related with a spot.\n\n- udf_spots_nearby_within_X_kilometers_from_current_user_position: get the places within 2 km (or you can custom) from the current position where you are. This search also include places of your friends.\n\n- udf_spots_nearby_by_filter_place_name.sql: get the places within 2 km (or you can custom) from the current position where you are, filter by a place name. This search also include places of your friends.\n\n- udf_spot_timeline_get.sql: get the places that belongs to my friends or me.\n\n- udf_spot_profile_get.sql: get the user profile of an account.\n\nb) schema -\u003e tables: examples tables. In \"spots\" table you can find PostGIS geometry columns (geom and position) used in the functions.\n\nc) schema -\u003e data: mock data.\n\n* Database model schema:\n\n![](https://github.com/LegolasVzla/pgplsql-useful-examples/blob/master/tree-postgis-queries/images/tree_postgis_queries_db_model.png \"Database_model_schema\")\n\n* Response status codes:\n\nudf_spots_nearby_within_X_kilometers_from_current_user_position return a response with the below standard:\n\n- Success case:\n\n\t{ \"status\" : \"success\", \"data\" : [{ }] }\n\n- Fail case:\n\n\t{ \"status\" : \"fail\", \"data\" : [{ } ]}\n\nSee more documentation in: [postgis](http://postgis.net/documentation/)\n\n## Plpython3u examples\n\nUse:\n\nAssuming you are on Ubuntu, install plpython3 as follow:\n\n\tsudo apt-get update\n\n\tsudo apt-get install postgresql-contrib postgresql-plpython3\n\nMove to the path where your clone this repository and then go to plpython3u-examples folder:\n\n\tcd plpython3u-examples/\n\nCreate your virtualenv and install the requirements:\n\n\tvirtualenv env --python=python3\n\tsource env/bin/activate\n\n\tpip install -r requirements.txt\n\nGive permissions to execute_all.sh file:\n\n\tchmod +x execute_all.sh\n\nLogin as a postgres user:\n\n\tsudo -i -u postgres\n\nFinally, execute the execute_all.sh file:\n\n\t./execute_all.sh\n\nStructure:\n\nFiles are contained inside of the temporal_schema folder, with the below structure:\n\na) schema -\u003e functions:\n\n- udf_reverse_geocoding_geopy: get full adress of a point from latitude and longitude parameters using geopy.\n\nSee more documentation in: [geopy](https://github.com/geopy/geopy)\n\nContributions\n-----------------------\n\nAll work to improve performance is good\n\nEnjoy it!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flegolasvzla%2Fpgplsql-useful-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flegolasvzla%2Fpgplsql-useful-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flegolasvzla%2Fpgplsql-useful-examples/lists"}