{"id":17196403,"url":"https://github.com/darold/uri","last_synced_at":"2025-09-08T06:36:12.444Z","repository":{"id":30787046,"uuid":"34343979","full_name":"darold/uri","owner":"darold","description":"uri is a extension to add uri data type for postgresql","archived":false,"fork":false,"pushed_at":"2025-01-07T22:33:28.000Z","size":130,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T20:51:55.882Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darold.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","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,"zenodo":null}},"created_at":"2015-04-21T18:11:55.000Z","updated_at":"2025-04-09T10:10:20.000Z","dependencies_parsed_at":"2024-12-31T06:17:29.232Z","dependency_job_id":"751e0493-8667-4c84-8708-40e2bda4192b","html_url":"https://github.com/darold/uri","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/darold/uri","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Furi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Furi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Furi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Furi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darold","download_url":"https://codeload.github.com/darold/uri/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Furi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274146258,"owners_count":25230115,"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-09-08T02:00:09.813Z","response_time":121,"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":[],"created_at":"2024-10-15T01:53:07.104Z","updated_at":"2025-09-08T06:36:12.408Z","avatar_url":"https://github.com/darold.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"PostgreSQL uri data type extension\n==================================\n\nuri is a extension to add uri data type for postgresql,\nit allows to insert data in uri format and provide all\nfunctions to extract uri parts, validate and compare uris.\nSome functions are provided to check if an uri exists,\ncheck size and content-type of remote uri (using libcurl)\nand local uri.\n\nIt has the following operators `=`, `\u003c\u003e`, `\u003c`, `\u003c=`, `\u003e`, `\u003e=`, `@\u003e`\nand `\u003c@`.\n\nuri columns can be indexed using btree and hash indexes.\n\nOnly hierarchical URI are supported by this extension. `http`, `file`, `ssh`,\n`telnet` and `ftp` scheme are hierarchical URI; `mailto`, `urn`, `tag` and `about`\naren't.\n\nRequirement\n-----------\n\nThe uri extension needs libcurl-dev to be installed:\n\n\tapt-get install libcurl4-openssl-dev\n\nor\n\n\tyum install libcurl-openssl-devel\n\nYou need to install [uriparser](http://uriparser.sourceforge.net/). Use\n\n\tapt-get install liburiparser1 liburiparser-dev\n\nor\n\n\tyum install uriparser uriparser-devel\n\nExtraction of mime type from a local file is done with the use of [libmagic](http://www.darwinsys.com/file/). libmagic\nis found with all Linux or BSD like distributions and comes with the `file` command, you will be able to install the\ndevelopment binary package using\n\n\tapt-get install libmagic-dev\n\nor\n\n\tyum install file-devel\n\n\nBuilding\n--------\n\nUse the following command to build and install the extension,\n`pg_config` must be in found from your PATH environment variable.\n\n\tmake\n\tsudo make install\n\nTo test the extension run:\n\n\tmake installcheck\n\nTo use the extension in your database execute:\n\n\tCREATE EXTENSION uri;\n\nFunctions\n---------\n\nThe extension provide some useful functions to access all parts of a URI\nper RFC 3986.\n\n- `uri_get_scheme(uri)` returns protocol part of uri as text\n- `uri_get_auth(uri)` returns user part of uri as text\n- `uri_get_host(uri)` returns host part of uri as text\n- `uri_get_port(uri)` returns port part of uri as text\n- `uri_get_portnum(uri)` returns port part uri as integer\n- `uri_get_path(uri)` returns path part of uri as text\n- `uri_get_query(uri)` returns query part of uri as text\n- `uri_get_fragment(uri)` returns fragment part of uri as text\n\nThe following are two URI examples and their component parts:\n\n         foo://example.com:8042/over/there?name=ferret#nose\n         \\_/   \\______________/\\_________/ \\_________/ \\__/\n          |           |            |            |        |\n       scheme     authority       path        query   fragment\n\nOther functions:\n\n- `uri_get_str(uri)` returns uri as text\n- `uri_is_absolute(uri)` returns true if uri is absolute\n- `uri_is_absolute_path(uri)` returns true if uri path is absolute\n- `uri_localpath_exists(uri)` returns true if uri exists as a regular local path (not symlink).\n- `uri_remotepath_exists(uri)` returns true if uri exists as a remote url.\n- `uri_path_exists(uri)` returns true if uri exists as a local regular path (not symlink) or remote url (local/remote is autodetected).\n- `uri_localpath_content_type(uri)` returns the content_type of a local file using libmagic.\n- `uri_remotepath_content_type(uri)` returns the content_type of a remote url.\n- `uri_path_content_type(uri)` returns the content_type of the url (local/remote is autodetected).\n- `uri_localpath_size(uri)` returns the size of a local regular file (not symlink).\n- `uri_remotepath_size(uri)` returns the size of a remote url.\n- `uri_path_size(uri)` returns the size of a local path (not symlink) or remote url (local/remote is autodetected).\n- `uri_escape(text)` returns the encoded URL of the given string using [curl_easy_escape()](https://curl.haxx.se/libcurl/c/curl_easy_escape.html).\n- `uri_unescape(text)` returns the decoded URL of the given string using [curl_easy_unescape()](https://curl.haxx.se/libcurl/c/curl_easy_unescape.html).\n- `uri_rebase_url(uri, uri)` returns the url resulting from a uri path rebased on an other uri. A base always end with a / any extra path after last / is removed from the base.\n- `uri_get_relative_path(uri, uri)` returns the path of a URI relative to its base.\n- `uri_remotepath_header(uri, text)` returns the HTTP header of the remote file as 'text' or 'json' following the format specified as second argument.\n\nNormalization\n------------\n\nIn all functions URIs are normalized as they are parsed.  Normalisation is performed according to section 6.2.2 of\nRFC3986, and includes adjusting the case of any scheme, hostname and percent-encoded characters so as to be\nconsistent, as well as removing redundant components from the path (for example, a path of `/a/b/c/../d/../../e` will\nbe normalised to `/a/e`).\n\nThis also mean that this extension stores normalized URI and not the original string. For example:\n\n\ttest_uri=# INSERT INTO t1 (url) VALUES ('file:///etc/postgresql/9.3/main/../../9.6/main/postgresql.conf');\n\tINSERT  0 1\n\ttest_uri=# SELECT * FROM t1 WHERE url = 'file:///etc/postgresql/9.3/main/../../9.6/main/postgresql.conf';\n\t id |                       url                       \n\t----+-------------------------------------------------\n\t  1 | file:///etc/postgresql/9.6/main/postgresql.conf\n\ttest_uri=# SELECT * FROM t1 WHERE url = 'file:///etc/postgresql/9.6/main/postgresql.conf';\n\t id |                       url                       \n\t----+-------------------------------------------------\n\t  1 | file:///etc/postgresql/9.6/main/postgresql.conf\n\nIf you want to retrieve the original value `file:///etc/postgresql/9.3/main/../../9.6/main/postgresql.conf`\nthis will not be possible anymore.\n\nMime type and size\n------------------\n\nFunction `uri_localpath_content_type()`, `uri_localpath_exists()`, `uri_localpath_size()`, `uri_remotepath_content_type()`,\n`uri_remotepath_exists()` and `uri_remotepath_size()` and so on meta function `uri_path_content_type()`, `uri_path_exists()`\nand `uri_path_size()` return NULL on uri access failure. The error returned by libcurl or the operating\nsystem you have to use your own script to test the URL. In the future this may change if users ask for a buildin\nfunction to report URL access error, at now I can't find any reason to do that.\n\nFunction `uri_remotepath_exists()` returns true when HTTP code returned by libcurl \u003c 400, false when HTTP code 404 is returned\nand NULL otherwise (HTTP code \u003e= 400).\n\nFunctions `uri_remotepath_content_type()` returns the content-type found by libcurl, NULL otherwise. A WARNING with the HTTP\nerror code is outputed on failure.\n\nFunction `uri_localpath_content_type()` returns the mime type of the file using libmagic, or the operating error message in\ncase of failure.\n\n\n\nOperators\n---------\n\n- `=`   check that 2 uri data are equals\n- `\u003c\u003e`  check that 2 uri data are different\n- `\u003c`   check that an uri is literally lower than an other\n- `\u003c=`  check that an uri is literally lower or equal than an other\n- `\u003e`   check that an uri is literally greater than an other\n- `\u003e=`  check that an uri is literally greater or equal than an other\n- `@\u003e`  check that left uri contains right uri\n- `\u003c@`  check that left uri is contained in right uri\n\n\nExamples\n--------\n\n\n\tCREATE EXTENSION uri;\n\n\tCREATE TABLE example (id integer, url uri);\n\n\tINSERT INTO example VALUES (1, 'http://pgcluu.darold.net/index.html#top');\n\tINSERT INTO example VALUES (2, 'file:///opt/git/uri/README');\n\tINSERT INTO example VALUES (3, 'http://mydomain.com/pub/../public/../index 1.html');\n\tINSERT INTO example VALUES (4, 'http://username:passwd@mydomain.com/pub/index.php?view=menu\u0026detail=1');\n\tINSERT INTO example VALUES (5, 'http://192.168.1.1/');\n\n\tSELECT * FROM example WHERE url='http://192.168.1.1/';\n\n\tSELECT uri_get_scheme(url), uri_get_host(url1) FROM example;\n\tSELECT uri_get_auth(url), uri_get_port(url1) FROM example;\n\tSELECT uri_get_path(url), uri_get_query(url1) FROM example;\n\tSELECT uri_get_fragment(url) FROM example;\n\n\tSELECT * FROM example WHERE uri_get_path(url)='/index.html';\n\tSELECT * FROM example WHERE uri_get_path(url) ~ '.*index.php';\n\n\tSELECT * FROM example WHERE url @\u003e '192.168.1.1';\n\tSELECT * FROM example WHERE '192.168.1.1' \u003c@ url;\n\nThe following example URIs illustrate several URI schemes and\nvariations in their common syntax components:\n\n\tINSERT INTO example VALUES (1, 'ftp://ftp.is.co.za/rfc/rfc1808.txt');\n\tINSERT INTO example VALUES (2, 'http://www.ietf.org/rfc/rfc2396.txt');\n\tINSERT INTO example VALUES (3, 'ldap://[2001:db8::7]/c=GB?objectClass?one');\n\tINSERT INTO example VALUES (4, 'telnet://192.0.2.16:80/');\n\tINSERT INTO example VALUES (5, 'file:///etc/postgresql/9.4/main/postgresql.conf.dist');\n\nIndexes\n-------\n\nIt is possible to create btree or hash indexes on uri data type.\n\n\tCREATE INDEX test2_index_uri ON example USING btree(url uri_btree_ops);\n\tCREATE INDEX test1_index_uri ON example USING hash(url uri_hash_ops);\n\nThe operator classes `uri_btree_ops` and `uri_hash_ops` can be omitted as they\nare used as default operator class for the uri data type. With these operator\nclasses, all URIs are normalized before they are compared. So if you search records\nwhere uri `file:///etc/postgresql/9.3/main/../../9.6/main/postgresql.conf` is found\nif will search for `file:///etc/postgresql/9.6/main/postgresql.conf` into the index\nor the table if the index is not used.\n\nAuthors\n-------\n\n* Gilles Darold\n\nLicense\n-------\n\nThis extension is free software distributed under the PostgreSQL Licence.\n\n- Copyright (c) 2015-2025, Gilles Darold\n\nSome parts of the code are original code copied from liburi licensed under\nthe terms of the Apache License, Version 2.0. The code have been embeded to\nthe extension to avoid dependencies requiring compilation from sources.\nliburi can be found here: [https://github.com/bbcarchdev/liburi](https://github.com/bbcarchdev/liburi)\n\n- Copyright (c) 2012 Mo McRoberts\n- Copyright (c) 2014-2017 BBC\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarold%2Furi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarold%2Furi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarold%2Furi/lists"}