{"id":20644034,"url":"https://github.com/adjust/pg-saturated_int","last_synced_at":"2025-06-11T02:32:39.197Z","repository":{"id":216849482,"uuid":"742513148","full_name":"adjust/pg-saturated_int","owner":"adjust","description":"An integer type with saturation arithmetic","archived":false,"fork":false,"pushed_at":"2024-02-09T17:06:47.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-03-09T14:42:04.856Z","etag":null,"topics":["adjust-kpis-team","adjust-pg-extension"],"latest_commit_sha":null,"homepage":"","language":"C","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/adjust.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}},"created_at":"2024-01-12T16:41:07.000Z","updated_at":"2024-11-12T09:54:06.000Z","dependencies_parsed_at":"2024-01-13T08:03:51.102Z","dependency_job_id":"0ce8dce1-4260-4d88-9ce7-54c9fd2144af","html_url":"https://github.com/adjust/pg-saturated_int","commit_stats":null,"previous_names":["adjust/pg-saturated_int"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpg-saturated_int","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpg-saturated_int/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpg-saturated_int/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpg-saturated_int/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adjust","download_url":"https://codeload.github.com/adjust/pg-saturated_int/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fpg-saturated_int/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259186274,"owners_count":22818532,"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":["adjust-kpis-team","adjust-pg-extension"],"created_at":"2024-11-16T16:14:36.885Z","updated_at":"2025-06-11T02:32:39.155Z","avatar_url":"https://github.com/adjust.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"![CI](https://github.com/adjust/pg-saturated_int/workflows/CI/badge.svg)\n\n# pg-saturated_int\n\nAn integer type with [saturation arithmetic](https://en.wikipedia.org/wiki/Saturation_arithmetic).\nThe difference from builtin integer type is that if an input value is out of allowed range\nthen the error `integer out of range` won't be raised.\n\n## Types\n\n### `saturated_int`\n\n`saturated_int` is an integer type which implements [saturation arithmetic](https://en.wikipedia.org/wiki/Saturation_arithmetic).\nAllowed range is `-2147483648` to `+2147483647`.\n\n```sql\n-- Cast to saturated_int\n\nselect 999999999999999::saturated_int;\n saturated_int \n---------------\n 2147483647\n\nselect 2147483648::saturated_int;\n saturated_int \n---------------\n 2147483647\n\nselect (-2147483649)::saturated_int;\n saturated_int \n---------------\n -2147483648\n```\n\n## Supported operators\n\n`saturated_int` supports comparison (`\u003c`, `\u003c=`, `\u003c\u003e`, `=`, `\u003e`, `\u003e=`) and arithmetic operators. Here is some examples:\n\n```sql\nselect 999999999999999::saturated_int \u003e 2147483648::saturated_int;\n ?column? \n----------\n f\n\nselect 999999999999999::saturated_int = 2147483648::saturated_int;\n ?column? \n----------\n t\n\nselect 999999999999999::saturated_int * 2147483648::saturated_int;\n  ?column?  \n------------\n 2147483647\n\nselect (-999999999999999)::saturated_int * 2147483648::saturated_int;\n  ?column?   \n-------------\n -2147483648\n\nselect 2147483648::saturated_int / (-1)::saturated_int;\n  ?column?   \n-------------\n -2147483647\n```\n\nNote that it is necessary to explicitly cast both of operands to `saturated_int`. Implicit cast isn't supported:\n\n```sql\nselect 2147483647::int = 2147483648::saturated_int;\nERROR:  operator does not exist: integer = saturated_int at character 24\n\nselect 2147483647::int * 2147483648::saturated_int;\nERROR:  operator does not exist: integer * saturated_int at character 24\n```\n\n## Index support\n\nThe extension supports `btree` and `hash` indexes.\n\n## Installation from source codes\n\nTo install `saturated_int`, execute this in the extension's directory:\n\n```shell\nmake install\n```\n\n\u003e **Notice:** Don't forget to set the `PG_CONFIG` variable (`make PG_CONFIG=...`)\n\u003e in case you want to test `saturated_int` on a non-default or custom build of PostgreSQL.\n\u003e Read more [here](https://wiki.postgresql.org/wiki/Building_and_Installing_PostgreSQL_Extension_Modules).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadjust%2Fpg-saturated_int","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadjust%2Fpg-saturated_int","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadjust%2Fpg-saturated_int/lists"}