Skip to content

Commit

Permalink
added support for style 126 and removed unncessary right padding
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Bhagat <[email protected]>
  • Loading branch information
Rohit Bhagat committed Jan 2, 2025
1 parent fe770c8 commit 784f948
Show file tree
Hide file tree
Showing 7 changed files with 556 additions and 71 deletions.
12 changes: 3 additions & 9 deletions contrib/babelfishpg_tsql/sql/sys_function_helpers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9953,8 +9953,6 @@ DECLARE
v_digits SMALLINT;
v_integral_digits SMALLINT;
v_decimal_digits SMALLINT;
v_res_length SMALLINT;
MASK_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\s*(?:character varying)\s*\(\s*(\d+|MAX)\s*\)\s*$';
v_result TEXT;
BEGIN
v_style := floor(p_style)::SMALLINT;
Expand All @@ -9974,18 +9972,14 @@ BEGIN
ELSE
v_result := substring(p_moneyval::PG_CATALOG.MONEY::TEXT, 2);
END IF;
ELSIF (v_style = 2) THEN
ELSIF (v_style = 2 OR v_style = 126) THEN
v_format := (pow(10, v_integral_digits)-10)::TEXT || 'D9999';
v_result := pg_catalog.btrim(to_char(v_moneyval, v_format));
ELSE
RAISE invalid_parameter_value;
END IF;
v_res_length := substring(p_datatype COLLATE "C", MASK_REGEXP)::SMALLINT;
IF v_res_length IS NULL THEN
RETURN v_result;
ELSE
RETURN rpad(v_result, v_res_length, ' ');
END IF;

RETURN v_result;
EXCEPTION
WHEN invalid_parameter_value THEN
RAISE USING MESSAGE := pg_catalog.format('%s is not a valid style number when converting from MONEY to a character string.', v_style),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ DECLARE
v_digits SMALLINT;
v_integral_digits SMALLINT;
v_decimal_digits SMALLINT;
v_res_length SMALLINT;
MASK_REGEXP CONSTANT VARCHAR COLLATE "C" := '^\s*(?:character varying)\s*\(\s*(\d+|MAX)\s*\)\s*$';
v_result TEXT;
BEGIN
v_style := floor(p_style)::SMALLINT;
Expand All @@ -168,18 +166,14 @@ BEGIN
ELSE
v_result := substring(p_moneyval::PG_CATALOG.MONEY::TEXT, 2);
END IF;
ELSIF (v_style = 2) THEN
ELSIF (v_style = 2 OR v_style = 126) THEN
v_format := (pow(10, v_integral_digits)-10)::TEXT || 'D9999';
v_result := pg_catalog.btrim(to_char(v_moneyval, v_format));
ELSE
RAISE invalid_parameter_value;
END IF;
v_res_length := substring(p_datatype COLLATE "C", MASK_REGEXP)::SMALLINT;
IF v_res_length IS NULL THEN
RETURN v_result;
ELSE
RETURN rpad(v_result, v_res_length, ' ');
END IF;

RETURN v_result;
EXCEPTION
WHEN invalid_parameter_value THEN
RAISE USING MESSAGE := pg_catalog.format('%s is not a valid style number when converting from MONEY to a character string.', v_style),
Expand Down
8 changes: 4 additions & 4 deletions test/JDBC/expected/BABEL-1531.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ SELECT CONVERT(varchar(50), CAST($23.12 AS money), 0);
GO
~~START~~
varchar
23.12
23.12
~~END~~

SELECT CONVERT(varchar(50), CAST($23.12 AS money), 2);
GO
~~START~~
varchar
23.1200
23.1200
~~END~~

SELECT CONVERT(varchar(50), CAST($23.12 as money));
GO
~~START~~
varchar
23.12
23.12
~~END~~

SELECT CONVERT(float, CAST($23.12 as money));
Expand Down Expand Up @@ -53,6 +53,6 @@ SELECT CONVERT(varchar(50), @mon);
GO
~~START~~
varchar
23.12
23.12
~~END~~

4 changes: 2 additions & 2 deletions test/JDBC/expected/BABEL-3486-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ SELECT * FROM BABEL_3486_vu_prepare_v54
GO
~~START~~
varchar
5.00
5.00
~~END~~

DROP VIEW BABEL_3486_vu_prepare_v54
Expand All @@ -1326,7 +1326,7 @@ EXEC BABEL_3486_vu_prepare_p54
GO
~~START~~
varchar
5.00
5.00
~~END~~

DROP PROCEDURE BABEL_3486_vu_prepare_p54
Expand Down
10 changes: 5 additions & 5 deletions test/JDBC/expected/babel_function.out
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,21 @@ select CONVERT(varchar(10), CAST(4936.56 AS MONEY), 0);
GO
~~START~~
varchar
4936.56
4936.56
~~END~~

select CONVERT(varchar(10), CAST(4936.56 AS MONEY), 1);
GO
~~START~~
varchar
4,936.56
4,936.56
~~END~~

select CONVERT(varchar(10), CAST(4936.56 AS MONEY), 2);
GO
~~START~~
varchar
4936.5600
4936.5600
~~END~~


Expand All @@ -212,7 +212,7 @@ SELECT CONVERT(int, 99.9);
GO
~~START~~
varchar
-4936.56
-4936.56
~~END~~

~~START~~
Expand Down Expand Up @@ -311,7 +311,7 @@ select TRY_CONVERT(varchar(10), CAST(4936.56 AS MONEY), 0);
GO
~~START~~
varchar
4936.56
4936.56
~~END~~


Expand Down
Loading

0 comments on commit 784f948

Please sign in to comment.