Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P51110
domain_index_to_domain
Active
Public
Actions
Authored by
bd808
on Aug 24 2023, 1:04 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Tags
None
Referenced Files
F37624354: raw-paste-data.txt
Aug 24 2023, 1:04 AM
2023-08-24 01:04:54 (UTC+0)
Subscribers
None
DELIMITER
$$
CREATE
OR
REPLACE
FUNCTION
domain_index_to_domain
(
_domain_index
TEXT
)
RETURNS
TEXT
DETERMINISTIC
BEGIN
DECLARE
_domain
TEXT
DEFAULT
NULL
;
DECLARE
_next
TEXT
DEFAULT
NULL
;
DECLARE
_nextlen
INT
DEFAULT
NULL
;
SET
_domain_index
=
TRIM
(
_domain_index
);
-- Move protocol to _domain
SET
_domain
=
CONCAT
(
SUBSTRING_INDEX
(
_domain_index
,
'://'
,
1
),
'://'
);
SET
_domain_index
=
SUBSTRING_INDEX
(
_domain_index
,
'://'
,
-
1
);
iterator
:
LOOP
-- exit loop when there's nothing left
IF
CHAR_LENGTH
(
TRIM
(
_domain_index
))
=
0
OR
_domain_index
IS
NULL
THEN
LEAVE
iterator
;
END
IF
;
SET
_next
=
SUBSTRING_INDEX
(
_domain_index
,
'.'
,
1
);
SET
_nextlen
=
CHAR_LENGTH
(
_next
);
SET
_domain
=
CONCAT
(
_domain
,
TRIM
(
_next
),
'.'
);
SET
_domain_index
=
INSERT
(
_domain_index
,
1
,
_nextlen
+
1
,
''
);
END
LOOP
;
RETURN
TRIM
(
TRAILING
'.'
FROM
_domain
);
END
;
$$
DELIMITER
;
Event Timeline
bd808
created this paste.
Aug 24 2023, 1:04 AM
2023-08-24 01:04:54 (UTC+0)
bd808
changed the title of this paste from untitled to
domain_index_to_domain
.
bd808
mentioned this in
T344877: SQL function to recover the normal hostname, to install on Wiki Replica instances
.
Aug 24 2023, 1:10 AM
2023-08-24 01:10:02 (UTC+0)
Log In to Comment