Skip to content

Commit 5b42015

Browse files
committed
Support u64 version parts in SQL function semver_no_prerelease
Fixes #1839.
1 parent 27e9619 commit 5b42015

File tree

2 files changed

+39
-0
lines changed
  • migrations/2019-09-18-233204_fix_int_type_in_to_semver_no_prerelease

2 files changed

+39
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
DROP FUNCTION to_semver_no_prerelease(text);
2+
DROP TYPE semver_triple;
3+
4+
-- Restores the type and function to what they were created as in
5+
-- migrations/20170308140537_create_to_semver_no_prerelease/up.sql
6+
7+
CREATE TYPE semver_triple AS (
8+
major int4,
9+
minor int4,
10+
teeny int4
11+
);
12+
13+
CREATE FUNCTION to_semver_no_prerelease(text) RETURNS semver_triple IMMUTABLE AS $$
14+
SELECT (
15+
split_part($1, '.', 1)::int4,
16+
split_part($1, '.', 2)::int4,
17+
split_part(split_part($1, '+', 1), '.', 3)::int4
18+
)::semver_triple
19+
WHERE strpos($1, '-') = 0
20+
$$ LANGUAGE SQL
21+
;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
DROP FUNCTION to_semver_no_prerelease(text);
2+
DROP TYPE semver_triple;
3+
4+
CREATE TYPE semver_triple AS (
5+
major numeric,
6+
minor numeric,
7+
teeny numeric
8+
);
9+
10+
CREATE FUNCTION to_semver_no_prerelease(text) RETURNS semver_triple IMMUTABLE AS $$
11+
SELECT (
12+
split_part($1, '.', 1)::numeric,
13+
split_part($1, '.', 2)::numeric,
14+
split_part(split_part($1, '+', 1), '.', 3)::numeric
15+
)::semver_triple
16+
WHERE strpos($1, '-') = 0
17+
$$ LANGUAGE SQL
18+
;

0 commit comments

Comments
 (0)