{"id":29892431,"url":"https://github.com/mfelici/fmt","last_synced_at":"2026-02-25T01:35:52.348Z","repository":{"id":193924394,"uuid":"247768978","full_name":"mfelici/fmt","owner":"mfelici","description":"Vertica User Defined SQL Function to format numbers","archived":false,"fork":false,"pushed_at":"2023-07-13T17:53:29.000Z","size":14,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-30T07:06:13.740Z","etag":null,"topics":["sql","userdefined-functions","vertica"],"latest_commit_sha":null,"homepage":null,"language":"PLSQL","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/mfelici.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}},"created_at":"2020-03-16T16:49:23.000Z","updated_at":"2022-12-06T13:20:26.000Z","dependencies_parsed_at":"2023-09-10T20:36:45.561Z","dependency_job_id":null,"html_url":"https://github.com/mfelici/fmt","commit_stats":null,"previous_names":["mfelici/fmt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mfelici/fmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Ffmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Ffmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Ffmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Ffmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfelici","download_url":"https://codeload.github.com/mfelici/fmt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Ffmt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29807994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T22:43:48.403Z","status":"ssl_error","status_checked_at":"2026-02-24T22:43:18.536Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["sql","userdefined-functions","vertica"],"created_at":"2025-08-01T02:00:56.515Z","updated_at":"2026-02-25T01:35:52.307Z","avatar_url":"https://github.com/mfelici.png","language":"PLSQL","readme":"﻿## What is FMT().\nFMT() is a simple Vertica User Defined SQL Function to format numbers... with thousand/decimal separators according to the server locale definition and round them... * the right way*. \n\nI know the standard ```TO_CHAR``` is implemented by several databases (including Vertica):\n```sql\nSELECT TO_CHAR(1234555677789.12345, '9G999G999G999G999D99') FROM DUAL;\n\n        TO_CHAR\n-----------------------\n1,234,555,677,789.12\n\n(1 row)\n```\nbut...\n1. it is too long to type for my taste\n2. they pretend me to know in advance the format of the output string and put the thousand **group separators** (G) in the right places\n3. it convert input numbers to FLOAT which can introduce approximations for very large numbers\n\n ```FMT()``` overcomes all these issues:\n - it's short to type\n - it will automatically insert a thousand separators every three digits *on its own*\n - it does not introduce approximations and can work with arbitrary long numbers.\n\n## What FMT() can be used for.\n```FMT()``` can be used to format numbers in output and you can call it using three different syntaxes:\n\n- ```FMT(number)``` will format the number adding thousand separators without decimals\n- ```FMT(number, #decimals)``` will add thousand separators and round to the specified decimals\n- ```FMT(number, #decimals, format)```will add thousand separators and round to the specified number of decimals using one of the following formats:\n\t-  ```N``` for numbers\n\t- ```P``` for percentages\n\t- ```T``` for per thousands \n\n## FMT() examples.\nHere you have a few examples:\n```SQL\nSELECT FMT(-1234);\n  FMT   \n--------\n -1,234\n(1 row)\n\nSELECT FMT(1234567890.98765);\n      FMT      \n---------------\n 1,234,567,890\n(1 row)\n\nSELECT FMT(1234567890.98765, 3);\n        FMT        \n-------------------\n 1,234,567,890.988\n(1 row)\n\nSELECT FMT(-1234566666666666677777777777777778888888888888889999999999999999.7896543, 4);\n                                             FMT                                             \n---------------------------------------------------------------------------------------------\n -1,234,566,666,666,666,677,777,777,777,777,778,888,888,888,888,889,999,999,999,999,999.7897\n(1 row)\n\nSELECT FMT(0.1234, 0, 'P');\n FMT \n-----\n 12%\n(1 row)\n\nSELECT FMT(0.1234621, 2, 'P');\n  FMT   \n--------\n 12.35%\n(1 row)\n\nSELECT FMT(0.00345432, 3, 'T');\n  FMT   \n--------\n 3.454‰\n(1 row)\n\nSELECT FMT(126.987654, 3, 'P');\n     FMT     \n-------------\n 12,698.765%\n(1 row)\n```\n## How to install FMT()\n- **First**... have a look to the ```Makefile```\n- **Second**, as dbadmin, deploy the code in Vertica: ```make deploy```\n- And, **finally**, you can ```make test``` and check everything is ok by comparing the output with the expected one here below...\n\nExpected output:\n```bash\n$ make deploy\nvsql -U dbadmin -X -f fmt.sql\nCREATE FUNCTION\nCREATE FUNCTION\nCREATE FUNCTION\nGRANT EXECUTE ON FUNCTION FMT(n NUMERIC) TO PUBLIC;\nGRANT EXECUTE ON FUNCTION FMT(n NUMERIC, d INTEGER) TO PUBLIC;\nGRANT EXECUTE ON FUNCTION FMT(n NUMERIC, d INTEGER, f VARCHAR) TO PUBLIC;\n\n$ make test\nSELECT FMT(-1234);\n   FMT\n--------\n-1,234\n\n(1 row) \n\nSELECT FMT(-1234567890);\n      FMT\n----------------\n-1,234,567,890\n\n(1 row)\n\nSELECT FMT(1234567890.98765);\n      FMT\n---------------\n1,234,567,890\n\n(1 row)\n\nSELECT FMT(1234567890.98765, 3);\n        FMT\n-------------------\n1,234,567,890.988\n\n(1 row)\n\nSELECT FMT(1234567890.98765, 3, 'N');\n        FMT\n-------------------\n1,234,567,890.988\n\n(1 row)\n\nSELECT FMT(-1234566666666666677777777777777778888888888888889999999999999999.7896543);\n                                         FMT\n----------------------------------------------------------------------------------------\n-1,234,566,666,666,666,677,777,777,777,777,778,888,888,888,888,889,999,999,999,999,999\n\n(1 row)\n\nSELECT FMT(-1234566666666666677777777777777778888888888888889999999999999999.7896543, 4, 'N');\n                                             FMT\n---------------------------------------------------------------------------------------------\n-1,234,566,666,666,666,677,777,777,777,777,778,888,888,888,888,889,999,999,999,999,999.7897\n\n(1 row)\n\nSELECT FMT(0.1234, 0, 'P');\n FMT\n-----\n 12%\n\n(1 row)\n\nSELECT FMT(0.1234621, 2, 'P');\n  FMT\n--------\n12.35%\n\n(1 row)\n \n\nSELECT FMT(0.00345432, 3, 'T');\n  FMT\n--------\n3.454‰\n\n(1 row)\n\nSELECT FMT(126.987654, 3, 'P');\n     FMT\n-------------\n12,698.765%\n\n(1 row)\n\n$ make clean\nDROP FUNCTION FMT(n NUMERIC) ;\nDROP FUNCTION\nDROP FUNCTION FMT(n NUMERIC, d INTEGER) ;\nDROP FUNCTION\nDROP FUNCTION FMT(n NUMERIC, d INTEGER, f VARCHAR) ;\nDROP FUNCTION\n```\n\n## Aknowledgments\nMany thanks to my colleagues :\n- Dinq-Qiang Liu (DQ)\n- Gianluigi Viganò (GG)\n- Maciej Paliwoda\n- Marco Gessner\n\nfor their suggestions.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfelici%2Ffmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfelici%2Ffmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfelici%2Ffmt/lists"}