|
| 1 | +URL type for PostgreSQL |
| 2 | +--------------------------- |
| 3 | + |
| 4 | +To register the new SQL type: |
| 5 | + |
| 6 | + CREATE EXTENSION url; |
| 7 | + |
| 8 | +URL Functions |
| 9 | + |
| 10 | +Function: to_url() |
| 11 | +Return Type: url |
| 12 | +Description: Returns the value as url. |
| 13 | +Example: to_url('https://example.com/'::text) |
| 14 | +Result: "https://example.com/" |
| 15 | + |
| 16 | +Function: url_base() |
| 17 | +Return Type: url |
| 18 | +Description: Returns url on the basis of absolute and relative url. |
| 19 | +Example: url_base('https://example.com/a/b/c/d/e/f'::url, '../../x/y/z'::text) |
| 20 | +Result: "https://example.com/a/b/c/x/y/z" |
| 21 | + |
| 22 | +Getters |
| 23 | + |
| 24 | +Function: scheme() |
| 25 | +Return Type: text |
| 26 | +Description: Returns scheme from the url if exists, otherwise NULL. |
| 27 | +Example: ('https://example.com/'::url).scheme |
| 28 | +Result: "https" |
| 29 | + |
| 30 | +Function: username() |
| 31 | +Return Type: text |
| 32 | +Description: Returns username from the url if exists, otherwise NULL. |
| 33 | +Example: ('https://root:qwerty@example.com/'::url).username |
| 34 | +Result: "root" |
| 35 | + |
| 36 | +Function: password() |
| 37 | +Return Type: text |
| 38 | +Description: Returns password from the url if exists, otherwise NULL. |
| 39 | +Example: ('https://root:qwerty@example.com/'::url).password |
| 40 | +Result: "qwerty" |
| 41 | + |
| 42 | +Function: host() |
| 43 | +Return Type: text |
| 44 | +Description: Returns host from the url if exists, otherwise NULL. |
| 45 | +Example: ('https://事例.com/'::url).host |
| 46 | +Result: "xn--3kq3x.com" |
| 47 | + |
| 48 | +Function: host_unicode() |
| 49 | +Return Type: text |
| 50 | +Description: Returns host as unicode from the url if exists, otherwise NULL. |
| 51 | +Example: ('https://事例.com/'::url).host_unicode |
| 52 | +Result: "事例.com" |
| 53 | + |
| 54 | +Function: port() |
| 55 | +Return Type: integer |
| 56 | +Description: Returns port from the url if exists, otherwise NULL. |
| 57 | +Example: ('https://example.com:8080/'::url).port |
| 58 | +Result: 8080 |
| 59 | + |
| 60 | +Function: path() |
| 61 | +Return Type: text |
| 62 | +Description: Returns path from the url. |
| 63 | +Example: ('https://example.com/path/to/home'::url).path |
| 64 | +Result: "/path/to/home" |
| 65 | + |
| 66 | +Function: query() |
| 67 | +Return Type: text |
| 68 | +Description: Returns query from the url if exists, otherwise NULL. |
| 69 | +Example: ('https://example.com?abc=xyz&1=2'::url).query |
| 70 | +Result: "abc=xyz&1=2" |
| 71 | + |
| 72 | +Function: fragment() |
| 73 | +Return Type: text |
| 74 | +Description: Returns fragment from the url if exists, otherwise NULL. |
| 75 | +Example: ('https://example.com#comments'::url).fragment |
| 76 | +Result: "comments" |
| 77 | + |
| 78 | + |
| 79 | +Setters |
| 80 | + |
| 81 | +Function: url_scheme_set(url, text) |
| 82 | +Return Type: url |
| 83 | +Description: Sets a new scheme for the url. |
| 84 | +Example: url_scheme_set('https://example.com'::url, 'wss') |
| 85 | +Result: "wss://example.com/" |
| 86 | + |
| 87 | +Function: url_username_set(url, text) |
| 88 | +Return Type: url |
| 89 | +Description: Sets a new username for the url. If the username is NULL or an empty value, it deletes it. |
| 90 | +Example: url_username_set('https://root:qwerty@example.com'::url, 'guest') |
| 91 | +Result: "https://guest:qwerty@example.com/" |
| 92 | + |
| 93 | +Function: url_password_set(url, text) |
| 94 | +Return Type: url |
| 95 | +Description: Sets a new password for the url. If the password is NULL or an empty value, it deletes it. |
| 96 | +Example: url_password_set('https://root:qwerty@example.com'::url, '12345') |
| 97 | +Result: "https://root:12345@example.com/" |
| 98 | + |
| 99 | +Function: url_host_set(url, text) |
| 100 | +Return Type: url |
| 101 | +Description: Sets a new host for the url. |
| 102 | +Example: url_host_set('https://example.com'::url, 'postgresql.org') |
| 103 | +Result: "https://postgresql.org/" |
| 104 | + |
| 105 | +Function: url_hostname_set(url, text) |
| 106 | +Return Type: url |
| 107 | +Description: Sets a new host for the url. |
| 108 | +Example: url_hostname_set('https://example.com'::url, 'postgresql.org') |
| 109 | +Result: "https://postgresql.org/" |
| 110 | + |
| 111 | +Function: url_port_set(url, text or integer) |
| 112 | +Return Type: url |
| 113 | +Description: Sets a new port for the url. If the port is NULL or an empty value, it deletes it. |
| 114 | +Example: url_port_set('https://example.com:8080'::url, '80') |
| 115 | +Result: "https://example.com:80/" |
| 116 | + |
| 117 | +Function: url_path_set(url, text) |
| 118 | +Return Type: url |
| 119 | +Description: Sets a new path for the url. If the path is NULL or an empty value, it deletes it. |
| 120 | +Example: url_path_set('https://example.com/path/to/home'::url, '/a/b/c') |
| 121 | +Result: "https://example.com/a/b/c" |
| 122 | + |
| 123 | +Function: url_query_set(url, text) |
| 124 | +Return Type: url |
| 125 | +Description: Sets a new query for the url. If the query is NULL or an empty value, it deletes it. |
| 126 | +Example: url_query_set('https://example.com?abc=xyz'::url, '123=abc') |
| 127 | +Result: "https://example.com/?123=abc" |
| 128 | + |
| 129 | +Function: url_fragment_set(url, text) |
| 130 | +Return Type: url |
| 131 | +Description: Sets a new fragment for the url. If the fragment is NULL or an empty value, it deletes it. |
| 132 | +Example: url_fragment_set('https://example.com#comment'::url, 'position') |
| 133 | +Result: "https://example.com/#position" |
| 134 | + |
| 135 | +NOTE: |
| 136 | +If you pass NULL as url, NULL will be returned. |
| 137 | + |
0 commit comments