{"id":23418725,"url":"https://github.com/mariadbjones/levenshtein-udf","last_synced_at":"2025-04-09T08:28:09.978Z","repository":{"id":175303425,"uuid":"172755125","full_name":"MariaDBJones/levenshtein-udf","owner":"MariaDBJones","description":"How to make levenshtein function a UDF","archived":false,"fork":false,"pushed_at":"2024-07-11T21:53:14.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T11:46:01.781Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","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/MariaDBJones.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-26T17:11:13.000Z","updated_at":"2024-07-11T21:53:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"66a59d51-5a30-4490-8fc3-550bce0675fb","html_url":"https://github.com/MariaDBJones/levenshtein-udf","commit_stats":null,"previous_names":["sylvaina77/levenshtein-udf","mariadbjones/levenshtein-udf"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariaDBJones%2Flevenshtein-udf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariaDBJones%2Flevenshtein-udf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariaDBJones%2Flevenshtein-udf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariaDBJones%2Flevenshtein-udf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MariaDBJones","download_url":"https://codeload.github.com/MariaDBJones/levenshtein-udf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248002372,"owners_count":21031588,"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":[],"created_at":"2024-12-23T00:34:06.555Z","updated_at":"2025-04-09T08:28:09.958Z","avatar_url":"https://github.com/MariaDBJones.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# levenshtein-udf\nHow to create a levenshtein function as a UDF in MariaDB / MySQL\n\n## Sources  \nThe sources are currently located in the root directory on the machine: [levenshteinUDF.c](https://github.com/SylvainA77/levenshtein-udf/blob/master/levenshteinUDF.c). These are calculation functions that I downloaded and converted into MySQL-compatible libraries. The specs for the overlay can be found here: https://dev.mysql.com/doc/refman/5.6/en/adding-udf.html  \nRecommendation: Save the sources in an SVN repository. [levenshteinSP.sql](https://github.com/SylvainA77/levenshtein-udf/blob/master/levenshteinSP.sql) is only presented so that one can benchmark by himself the performance of compiled UDF.\n\n## Libraries  \nThe aforementioned sources are compiled into libraries using gcc : **gcc -o levenshteinUDF.so -shared levenshteinUDF.c `mysql_config --cflags` -fPIC** . It is crucial not to forget the -shared flag during compilation; otherwise, creating the function in MySQL will not go smoothly.\nRecommendation: Place the libraries (the levenshteinUDF.so file in our case) in the /lib directory of the machine and then create a symbolic link of the same name from _/usr/local/mysql/lib/plugin_. This way, a program that needs to call these functions won't have to go through the database.\n\n## Functions  \nFinally, you need to create the functions in MySQL to use them in queries. Use the following command: _CREATE FUNCTION \u003cfunction_name_in_library\u003e RETURNS \u003cexpected_return_variable_type\u003e SONAME '\u003clibrary_name_with_extension_but_without_path\u003e';_\nExample: In the levenshtein.so library, we have three functions: levenshtein, levenshtein_k, and levenshtein_ratio. The first two return an integer, while the last one, which we are interested in, returns a real number. To create the function in MySQL, use the following command: **CREATE FUNCTION levenshtein_ratio RETURNS REAL SONAME 'levenshteinUDF.so';**\nWe can now use it like any other function in a query.\n\nTip: The list of UDFs can be found using this query: _SELECT * FROM mysql.func_.\n\nMentioned in [![Mentioned in Awesome MariaDB](https://awesome.re/mentioned-badge.svg)](https://github.com/Vettabase/awesome-mariadb)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariadbjones%2Flevenshtein-udf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmariadbjones%2Flevenshtein-udf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariadbjones%2Flevenshtein-udf/lists"}