{"id":14974050,"url":"https://github.com/array-analytics/plpg_hashids","last_synced_at":"2025-10-27T05:31:27.720Z","repository":{"id":45562453,"uuid":"181926629","full_name":"array-analytics/plpg_hashids","owner":"array-analytics","description":"Short unique id generator for PostgreSQL in plpgsql, using hashids.org","archived":false,"fork":false,"pushed_at":"2022-08-17T21:03:44.000Z","size":47,"stargazers_count":36,"open_issues_count":5,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-01T02:41:27.635Z","etag":null,"topics":["plpgsql","postgresql"],"latest_commit_sha":null,"homepage":"","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/array-analytics.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}},"created_at":"2019-04-17T16:12:53.000Z","updated_at":"2024-05-22T10:41:40.000Z","dependencies_parsed_at":"2022-09-23T05:10:23.339Z","dependency_job_id":null,"html_url":"https://github.com/array-analytics/plpg_hashids","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/array-analytics%2Fplpg_hashids","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/array-analytics%2Fplpg_hashids/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/array-analytics%2Fplpg_hashids/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/array-analytics%2Fplpg_hashids/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/array-analytics","download_url":"https://codeload.github.com/array-analytics/plpg_hashids/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238445840,"owners_count":19473821,"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","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":["plpgsql","postgresql"],"created_at":"2024-09-24T13:49:52.796Z","updated_at":"2025-10-27T05:31:27.353Z","avatar_url":"https://github.com/array-analytics.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# plpg_hashids\nA small set of TSQL functions to generate YouTube-like hashes from one or many numbers. \nUse hashids when you do not want to expose your database ids to the user.\n\n[http://www.hashids.org/](http://www.hashids.org/)\n\nThis repository contains a port to plpgsql of the other projects found at hashids.org.\nThe [TSQL](https://github.com/waynebloss/hashids-tsql), [Postgres](https://github.com/iCyberon/pg_hashids), [Javascript](https://github.com/ivanakimov/hashids.js) and [.NET](https://github.com/ullmark/hashids.net) versions of Hashids are the primary reference projects for this port, with the TSQL version being the initial version.\n\nTested PostgreSQL versions : 9.6.X (Should work on older and newer versions, just not tested)\n\n**It was done using plpgsql becuase, Azure and AWS don't allow creating your own extensions when running on their platform, and pg_hashids isn't a supported extension.**\n\n## What is it?\n\nhashids (Hash ID's) creates short, unique, decryptable hashes from unsigned integers.\n\n_(NOTE: This is **NOT** a true cryptographic hash, since it is reversible.)_\n\nIt was designed for websites to use in URL shortening, tracking stuff, or making pages private (or at least unguessable).\n\nThis algorithm tries to satisfy the following requirements:\n\n1. Hashes must be unique and decryptable.\n2. They should be able to contain more than one integer (so you can use them in complex or clustered systems).\n3. You should be able to specify minimum hash length.\n4. Hashes should not contain basic English curse words (since they are meant to appear in public places - like the URL).\n\nInstead of showing items as `1`, `2`, or `3`, you could show them as `U6dc`, `u87U`, and `HMou`.\nYou can choose to store these hashes in the database or encrypt + decrypt on the fly.\n\nAll integers need to be greater than or equal to zero.\n\nSee [hashids.org](http://www.hashids.org/) for more information on this technique.\n\n## Usage\n\nRun the scripts in the order that they are in, in the `src` folder. Please note, that they are in their own schema (`hashids`), if you don't want that you will have to edit the scripts to remove the assumption of the `hashids` schema.\n\n#### Encoding\nReturns a hash using the default `alphabet` and empty `salt`.\n\n\tSELECT hashids.encode(1001); -- Result: jNl\n\nReturns a hash using the default `alphabet` and supplied `salt`.\n\n\tSELECT hashids.encode(1234567, 'This is my salt'); -- Result: Pdzxp\n\nReturns a hash using the default `alphabet`, `salt` and minimum hash length.\n\t\n\tSELECT hashids.encode(1234567, 'This is my salt', 10); -- Result: PlRPdzxpR7\n\t\nReturns a hash using the supplied `alphabet`, `salt` and minimum hash length.\n\t\n\tSELECT hashids.encode(1234567, 'This is my salt', 10, 'abcdefghijABCDxFGHIJ1234567890'); -- Result: 3GJ956J9B9\n\nReturns a hash for an array of numbers.\n\n\tSELECT hashids.encode_list(ARRAY[1,2,3]); -- Result: o2fXhV\n  \n#### Decoding\nYou can also decode previously generated hashes. Just use the same `salt`, otherwise you'll get wrong results.\n\n\tSELECT unnest(hashids.decode('PlRPdzxpR7', 'This is my salt', 10)); -- Result: 1234567\n\t\nUsing a custom alphabet\n\n\tSELECT unnest(hashids.decode('3GJ956J9B9', 'This is my salt', 10, 'abcdefghijABCDxFGHIJ1234567890')); -- Result: 1234567\n\t\n# Note\nThe code and scripts are provided as is.  Array Analytics isn't responsible if anything bad happens.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farray-analytics%2Fplpg_hashids","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farray-analytics%2Fplpg_hashids","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farray-analytics%2Fplpg_hashids/lists"}