diff --git a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql index 99d5c59f2e..43830587cf 100644 --- a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql +++ b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql @@ -9849,9 +9849,9 @@ BEGIN END IF; WHEN 'sys.money'::regtype THEN IF v_style = -1 THEN - RETURN sys.babelfish_try_conv_money_to_string(typename, arg::numeric(19,4)::pg_catalog.money); + RETURN sys.babelfish_try_conv_money_to_string(typename, arg::numeric(19,4)); ELSE - RETURN sys.babelfish_try_conv_money_to_string(typename, arg::numeric(19,4)::pg_catalog.money, p_style); + RETURN sys.babelfish_try_conv_money_to_string(typename, arg::numeric(19,4), p_style); END IF; ELSE RETURN CAST(arg AS sys.VARCHAR); @@ -9939,7 +9939,7 @@ LANGUAGE plpgsql STABLE; CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_money_to_string(IN p_datatype TEXT, - IN p_moneyval PG_CATALOG.MONEY, + IN p_moneyval NUMERIC, IN p_style NUMERIC DEFAULT 0) RETURNS TEXT AS @@ -9966,17 +9966,17 @@ BEGIN v_integral_digits := v_digits; END IF; IF (v_style = 0) THEN - v_format := (pow(10, v_integral_digits)-1)::TEXT || 'D99'; - v_result := to_char(v_moneyval, v_format); + v_format := (pow(10, v_integral_digits)-10)::TEXT || 'D99'; + v_result := pg_catalog.btrim(to_char(v_moneyval, v_format)); ELSIF (v_style = 1) THEN - IF (v_moneysign::SMALLINT = 1) THEN - v_result := substring(p_moneyval::TEXT, 2); + IF (v_moneysign::SMALLINT = -1) THEN + v_result := substring(p_moneyval::PG_CATALOG.MONEY::TEXT, 1, 1) || substring(p_moneyval::PG_CATALOG.MONEY::TEXT, 3); ELSE - v_result := substring(p_moneyval::TEXT, 1, 1) || substring(p_moneyval::TEXT, 3); + v_result := substring(p_moneyval::PG_CATALOG.MONEY::TEXT, 2); END IF; ELSIF (v_style = 2) THEN - v_format := (pow(10, v_integral_digits)-1)::TEXT || 'D9999'; - v_result := to_char(v_moneyval, v_format); + 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; diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql index 09c2678aec..3fdc202a45 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.0.0--5.1.0.sql @@ -3,6 +3,36 @@ -- add 'sys' to search path for the convenience SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false); +-- Drops an object if it does not have any dependent objects. +-- Is a temporary procedure for use by the upgrade script. Will be dropped at the end of the upgrade. +-- Please have this be one of the first statements executed in this upgrade script. +CREATE OR REPLACE PROCEDURE babelfish_drop_deprecated_object(object_type varchar, schema_name varchar, object_name varchar) AS +$$ +DECLARE + error_msg text; + query1 text; + query2 text; +BEGIN + + query1 := pg_catalog.format('alter extension babelfishpg_tsql drop %s %s.%s', object_type, schema_name, object_name); + query2 := pg_catalog.format('drop %s %s.%s', object_type, schema_name, object_name); + + execute query1; + execute query2; +EXCEPTION + when object_not_in_prerequisite_state then --if 'alter extension' statement fails + GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; + raise warning '%', error_msg; + when dependent_objects_still_exist then --if 'drop view' statement fails + GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; + raise warning '%', error_msg; + when undefined_function then --if 'Deprecated function does not exist' + GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; + raise warning '%', error_msg; +end +$$ +LANGUAGE plpgsql; + CREATE OR REPLACE FUNCTION sys.babelfish_update_server_collation_name() RETURNS VOID LANGUAGE C AS 'babelfishpg_common', 'babelfish_update_server_collation_name'; @@ -40,6 +70,133 @@ $$; * final behaviour. */ +CREATE OR REPLACE FUNCTION sys.babelfish_conv_to_varchar(IN typename TEXT, + IN arg anyelement, + IN p_style NUMERIC DEFAULT -1) +RETURNS sys.VARCHAR +AS +$BODY$ +DECLARE + v_style SMALLINT; +BEGIN + v_style := floor(p_style)::SMALLINT; + + CASE pg_typeof(arg) + WHEN 'date'::regtype THEN + IF v_style = -1 THEN + RETURN sys.babelfish_try_conv_date_to_string(typename, arg); + ELSE + RETURN sys.babelfish_try_conv_date_to_string(typename, arg, p_style); + END IF; + WHEN 'time'::regtype THEN + IF v_style = -1 THEN + RETURN sys.babelfish_try_conv_time_to_string(typename, 'TIME', arg); + ELSE + RETURN sys.babelfish_try_conv_time_to_string(typename, 'TIME', arg, p_style); + END IF; + WHEN 'sys.datetime'::regtype THEN + IF v_style = -1 THEN + RETURN sys.babelfish_try_conv_datetime_to_string(typename, 'DATETIME', arg::timestamp); + ELSE + RETURN sys.babelfish_try_conv_datetime_to_string(typename, 'DATETIME', arg::timestamp, p_style); + END IF; + WHEN 'float'::regtype THEN + IF v_style = -1 THEN + RETURN sys.babelfish_try_conv_float_to_string(typename, arg); + ELSE + RETURN sys.babelfish_try_conv_float_to_string(typename, arg, p_style); + END IF; + WHEN 'sys.money'::regtype THEN + IF v_style = -1 THEN + RETURN sys.babelfish_try_conv_money_to_string(typename, arg::numeric(19,4)); + ELSE + RETURN sys.babelfish_try_conv_money_to_string(typename, arg::numeric(19,4), p_style); + END IF; + ELSE + RETURN CAST(arg AS sys.VARCHAR); + END CASE; +END; +$BODY$ +LANGUAGE plpgsql +STABLE; + +DO $$ +DECLARE + exception_message text; +BEGIN + ALTER FUNCTION sys.babelfish_try_conv_money_to_string(TEXT, PG_CATALOG.MONEY, NUMERIC) RENAME TO babelfish_try_conv_money_to_string_deprecated_in_5_1_0; +EXCEPTION WHEN OTHERS THEN + GET STACKED DIAGNOSTICS + exception_message = MESSAGE_TEXT; + RAISE WARNING '%', exception_message; +END; +$$; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_money_to_string(IN p_datatype TEXT, + IN p_moneyval NUMERIC, + IN p_style NUMERIC DEFAULT 0) +RETURNS TEXT +AS +$BODY$ +DECLARE + v_style SMALLINT; + v_format VARCHAR COLLATE "C"; + v_moneyval NUMERIC(19,4) := p_moneyval::NUMERIC(19,4); + v_moneysign NUMERIC(19,4) := sign(v_moneyval); + v_moneyabs NUMERIC(19,4) := abs(v_moneyval); + 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; + v_digits := length(v_moneyabs::TEXT); + v_decimal_digits := scale(v_moneyabs); + IF (v_decimal_digits > 0) THEN + v_integral_digits := v_digits - v_decimal_digits - 1; + ELSE + v_integral_digits := v_digits; + END IF; + IF (v_style = 0) THEN + v_format := (pow(10, v_integral_digits)-10)::TEXT || 'D99'; + v_result := pg_catalog.btrim(to_char(v_moneyval, v_format)); + ELSIF (v_style = 1) THEN + IF (v_moneysign::SMALLINT = -1) THEN + v_result := substring(p_moneyval::PG_CATALOG.MONEY::TEXT, 1, 1) || substring(p_moneyval::PG_CATALOG.MONEY::TEXT, 3); + ELSE + v_result := substring(p_moneyval::PG_CATALOG.MONEY::TEXT, 2); + END IF; + ELSIF (v_style = 2) 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; +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), + DETAIL := 'Use of incorrect "style" parameter value during conversion process.', + HINT := 'Change "style" parameter to the proper value and try again.'; +END; +$BODY$ +LANGUAGE plpgsql +STABLE +RETURNS NULL ON NULL INPUT; + +CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_try_conv_money_to_string_deprecated_in_5_1_0'); + +-- Drops the temporary procedure used by the upgrade script. +-- Please have this be one of the last statements executed in this upgrade script. +DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar); + -- After upgrade, always run analyze for all babelfish catalogs. CALL sys.analyze_babelfish_catalogs(); -- Reset search_path to not affect any subsequent scripts diff --git a/test/JDBC/expected/BABEL-1531.out b/test/JDBC/expected/BABEL-1531.out index a36e32c904..d661a5d159 100644 --- a/test/JDBC/expected/BABEL-1531.out +++ b/test/JDBC/expected/BABEL-1531.out @@ -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)); @@ -53,6 +53,6 @@ SELECT CONVERT(varchar(50), @mon); GO ~~START~~ varchar - 23.12 +23.12 ~~END~~ diff --git a/test/JDBC/expected/BABEL-3486-vu-verify.out b/test/JDBC/expected/BABEL-3486-vu-verify.out index 6039b8e898..59777fd8fc 100644 --- a/test/JDBC/expected/BABEL-3486-vu-verify.out +++ b/test/JDBC/expected/BABEL-3486-vu-verify.out @@ -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 @@ -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 diff --git a/test/JDBC/expected/babel_function.out b/test/JDBC/expected/babel_function.out index 7fc4b20e46..13584b355a 100644 --- a/test/JDBC/expected/babel_function.out +++ b/test/JDBC/expected/babel_function.out @@ -188,7 +188,7 @@ 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); @@ -202,7 +202,7 @@ select CONVERT(varchar(10), CAST(4936.56 AS MONEY), 2); GO ~~START~~ varchar - 4936.5600 +4936.5600 ~~END~~ @@ -311,7 +311,7 @@ select TRY_CONVERT(varchar(10), CAST(4936.56 AS MONEY), 0); GO ~~START~~ varchar - 4936.56 +4936.56 ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_function.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_function.out index 31870b6ade..56c2a1b2f8 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_function.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_function.out @@ -188,7 +188,7 @@ 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); @@ -202,7 +202,7 @@ select CONVERT(varchar(10), CAST(4936.56 AS MONEY), 2); GO ~~START~~ varchar - 4936.5600 +4936.5600 ~~END~~ @@ -311,7 +311,7 @@ select TRY_CONVERT(varchar(10), CAST(4936.56 AS MONEY), 0); GO ~~START~~ varchar - 4936.56 +4936.56 ~~END~~ diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out new file mode 100644 index 0000000000..de0c5e4c6e --- /dev/null +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-cleanup.out @@ -0,0 +1,11 @@ +DROP VIEW test_conv_string_to_date_v1 +GO + +DROP PROCEDURE test_conv_string_to_date_p1 +GO + +DROP FUNCTION test_conv_string_to_date_f1 +GO + +DROP TABLE test_conv_money_to_varchar_t1 +GO diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out new file mode 100644 index 0000000000..559ceae53b --- /dev/null +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-prepare.out @@ -0,0 +1,39 @@ +CREATE TABLE test_conv_money_to_varchar_t1(val money) +GO + +INSERT INTO test_conv_money_to_varchar_t1 VALUES (1234), (0), (123.12), (0.12456) +GO +~~ROW COUNT: 4~~ + + +CREATE VIEW test_conv_string_to_date_v1 as ( + SELECT val, + val_convert = '$' + CONVERT(VARCHAR, val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, val, 2) + FROM test_conv_money_to_varchar_t1 +); +GO + +CREATE PROCEDURE test_conv_string_to_date_p1 as ( + SELECT val, + val_convert = '$' + CONVERT(VARCHAR, val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, val, 2) + FROM test_conv_money_to_varchar_t1 +); +GO + +CREATE FUNCTION test_conv_string_to_date_f1() +RETURNS TABLE AS +RETURN ( + SELECT val, + val_convert = '$' + CONVERT(VARCHAR, val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, val, 2) + FROM test_conv_money_to_varchar_t1 +); +GO diff --git a/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out b/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out new file mode 100644 index 0000000000..9f708e2229 --- /dev/null +++ b/test/JDBC/expected/test_conv_money_to_varchar-vu-verify.out @@ -0,0 +1,113 @@ +DECLARE @val MONEY = 1234 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +1234.0000#!#$1234.00#!#$1234.00#!#$1,234.00#!#$1234.0000 +~~END~~ + + +DECLARE @val MONEY = 0 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +0.0000#!#$0.00#!#$0.00#!#$0.00#!#$0.0000 +~~END~~ + + +DECLARE @val MONEY = 123.12 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +123.1200#!#$123.12#!#$123.12#!#$123.12#!#$123.1200 +~~END~~ + + +DECLARE @val MONEY = 0.12456 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +0.1246#!#$0.12#!#$0.12#!#$0.12#!#$0.1246 +~~END~~ + + +DECLARE @val MONEY = 123456789123456.12456 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +123456789123456.1246#!#$123456789123456.12#!#$123456789123456.12#!#$123,456,789,123,456.12#!#$123456789123456.1246 +~~END~~ + + + +SELECT val, + val_convert = '$' + CONVERT(VARCHAR, val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, val, 2) +FROM test_conv_money_to_varchar_t1 +-- Dependent objects +SELECT * FROM test_conv_string_to_date_v1 +GO +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +1234.0000#!#$1234.00#!#$1234.00#!#$1,234.00#!#$1234.0000 +0.0000#!#$0.00#!#$0.00#!#$0.00#!#$0.0000 +123.1200#!#$123.12#!#$123.12#!#$123.12#!#$123.1200 +0.1246#!#$0.12#!#$0.12#!#$0.12#!#$0.1246 +~~END~~ + +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +1234.0000#!#$1234.00#!#$1234.00#!#$1,234.00#!#$1234.0000 +0.0000#!#$0.00#!#$0.00#!#$0.00#!#$0.0000 +123.1200#!#$123.12#!#$123.12#!#$123.12#!#$123.1200 +0.1246#!#$0.12#!#$0.12#!#$0.12#!#$0.1246 +~~END~~ + + +EXEC test_conv_string_to_date_p1 +GO +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +1234.0000#!#$1234.00#!#$1234.00#!#$1,234.00#!#$1234.0000 +0.0000#!#$0.00#!#$0.00#!#$0.00#!#$0.0000 +123.1200#!#$123.12#!#$123.12#!#$123.12#!#$123.1200 +0.1246#!#$0.12#!#$0.12#!#$0.12#!#$0.1246 +~~END~~ + + +SELECT * FROM test_conv_string_to_date_f1() +GO +~~START~~ +money#!#varchar#!#varchar#!#varchar#!#varchar +1234.0000#!#$1234.00#!#$1234.00#!#$1,234.00#!#$1234.0000 +0.0000#!#$0.00#!#$0.00#!#$0.00#!#$0.0000 +123.1200#!#$123.12#!#$123.12#!#$123.12#!#$123.1200 +0.1246#!#$0.12#!#$0.12#!#$0.12#!#$0.1246 +~~END~~ + diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql new file mode 100644 index 0000000000..de0c5e4c6e --- /dev/null +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-cleanup.sql @@ -0,0 +1,11 @@ +DROP VIEW test_conv_string_to_date_v1 +GO + +DROP PROCEDURE test_conv_string_to_date_p1 +GO + +DROP FUNCTION test_conv_string_to_date_f1 +GO + +DROP TABLE test_conv_money_to_varchar_t1 +GO diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql new file mode 100644 index 0000000000..9cbe407788 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-prepare.sql @@ -0,0 +1,37 @@ +CREATE TABLE test_conv_money_to_varchar_t1(val money) +GO + +INSERT INTO test_conv_money_to_varchar_t1 VALUES (1234), (0), (123.12), (0.12456) +GO + +CREATE VIEW test_conv_string_to_date_v1 as ( + SELECT val, + val_convert = '$' + CONVERT(VARCHAR, val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, val, 2) + FROM test_conv_money_to_varchar_t1 +); +GO + +CREATE PROCEDURE test_conv_string_to_date_p1 as ( + SELECT val, + val_convert = '$' + CONVERT(VARCHAR, val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, val, 2) + FROM test_conv_money_to_varchar_t1 +); +GO + +CREATE FUNCTION test_conv_string_to_date_f1() +RETURNS TABLE AS +RETURN ( + SELECT val, + val_convert = '$' + CONVERT(VARCHAR, val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, val, 2) + FROM test_conv_money_to_varchar_t1 +); +GO diff --git a/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql new file mode 100644 index 0000000000..8b45148d25 --- /dev/null +++ b/test/JDBC/input/functions/test_conv_money_to_varchar-vu-verify.sql @@ -0,0 +1,56 @@ +DECLARE @val MONEY = 1234 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO + +DECLARE @val MONEY = 0 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO + +DECLARE @val MONEY = 123.12 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO + +DECLARE @val MONEY = 0.12456 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO + +DECLARE @val MONEY = 123456789123456.12456 +SELECT @val, + val_convert = '$' + CONVERT(VARCHAR, @val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, @val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, @val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, @val, 2); +GO + +SELECT val, + val_convert = '$' + CONVERT(VARCHAR, val) , + val_convert_style_0 = '$' + CONVERT(VARCHAR, val, 0), + val_convert_style_1 = '$' + CONVERT(VARCHAR, val, 1), + val_convert_style_2 = '$' + CONVERT(VARCHAR, val, 2) +FROM test_conv_money_to_varchar_t1 + +-- Dependent objects +SELECT * FROM test_conv_string_to_date_v1 +GO + +EXEC test_conv_string_to_date_p1 +GO + +SELECT * FROM test_conv_string_to_date_f1() +GO diff --git a/test/JDBC/upgrade/13_4/schedule b/test/JDBC/upgrade/13_4/schedule index 75771952f2..c95134772c 100644 --- a/test/JDBC/upgrade/13_4/schedule +++ b/test/JDBC/upgrade/13_4/schedule @@ -253,4 +253,5 @@ binary-datatype-operators BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5059-before-14_7-or-15_2 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/13_5/schedule b/test/JDBC/upgrade/13_5/schedule index debb792c0f..1ded1773c1 100644 --- a/test/JDBC/upgrade/13_5/schedule +++ b/test/JDBC/upgrade/13_5/schedule @@ -306,4 +306,5 @@ BABEL-5059-before-14_7-or-15_2 replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/13_6/schedule b/test/JDBC/upgrade/13_6/schedule index 630f602183..bd682f7480 100644 --- a/test/JDBC/upgrade/13_6/schedule +++ b/test/JDBC/upgrade/13_6/schedule @@ -363,3 +363,4 @@ replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/13_7/schedule b/test/JDBC/upgrade/13_7/schedule index f2c678f230..3cdedc90db 100644 --- a/test/JDBC/upgrade/13_7/schedule +++ b/test/JDBC/upgrade/13_7/schedule @@ -356,4 +356,5 @@ replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/13_8/schedule b/test/JDBC/upgrade/13_8/schedule index 2b0ce2a271..4998e118fc 100644 --- a/test/JDBC/upgrade/13_8/schedule +++ b/test/JDBC/upgrade/13_8/schedule @@ -356,4 +356,5 @@ replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/13_9/schedule b/test/JDBC/upgrade/13_9/schedule index 23c12873f4..86ed32ab15 100644 --- a/test/JDBC/upgrade/13_9/schedule +++ b/test/JDBC/upgrade/13_9/schedule @@ -361,4 +361,5 @@ replace-before-15_8-or-16_4 BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index dbf13a2b0b..7cd7f8f988 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -474,4 +474,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_11/schedule b/test/JDBC/upgrade/14_11/schedule index 694153db54..4dffd0444a 100644 --- a/test/JDBC/upgrade/14_11/schedule +++ b/test/JDBC/upgrade/14_11/schedule @@ -472,4 +472,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_12/schedule b/test/JDBC/upgrade/14_12/schedule index 9a8a0592b8..1ef6908585 100644 --- a/test/JDBC/upgrade/14_12/schedule +++ b/test/JDBC/upgrade/14_12/schedule @@ -473,4 +473,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_13/schedule b/test/JDBC/upgrade/14_13/schedule index 0e089fea64..1803d69543 100644 --- a/test/JDBC/upgrade/14_13/schedule +++ b/test/JDBC/upgrade/14_13/schedule @@ -473,4 +473,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_15/schedule b/test/JDBC/upgrade/14_15/schedule index 23483d79a2..67c62fa7fb 100644 --- a/test/JDBC/upgrade/14_15/schedule +++ b/test/JDBC/upgrade/14_15/schedule @@ -469,3 +469,4 @@ xml_exist-before-16_5 BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_16/schedule b/test/JDBC/upgrade/14_16/schedule index 132b4e6796..5e3238e291 100644 --- a/test/JDBC/upgrade/14_16/schedule +++ b/test/JDBC/upgrade/14_16/schedule @@ -469,3 +469,4 @@ xml_exist-before-16_5 BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_3/schedule b/test/JDBC/upgrade/14_3/schedule index 39ca14015b..dbfc2c34c0 100644 --- a/test/JDBC/upgrade/14_3/schedule +++ b/test/JDBC/upgrade/14_3/schedule @@ -392,4 +392,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_5/schedule b/test/JDBC/upgrade/14_5/schedule index 3f176f7b99..d4413f24b1 100644 --- a/test/JDBC/upgrade/14_5/schedule +++ b/test/JDBC/upgrade/14_5/schedule @@ -404,4 +404,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_6/schedule b/test/JDBC/upgrade/14_6/schedule index 82edbaa3a8..517bf3906d 100644 --- a/test/JDBC/upgrade/14_6/schedule +++ b/test/JDBC/upgrade/14_6/schedule @@ -442,4 +442,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_7/schedule b/test/JDBC/upgrade/14_7/schedule index d525e680be..e41900f13c 100644 --- a/test/JDBC/upgrade/14_7/schedule +++ b/test/JDBC/upgrade/14_7/schedule @@ -464,4 +464,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_8/schedule b/test/JDBC/upgrade/14_8/schedule index 088ab57d9c..4cff0d8503 100644 --- a/test/JDBC/upgrade/14_8/schedule +++ b/test/JDBC/upgrade/14_8/schedule @@ -466,4 +466,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/14_9/schedule b/test/JDBC/upgrade/14_9/schedule index 08168dda66..17e7c0bdab 100644 --- a/test/JDBC/upgrade/14_9/schedule +++ b/test/JDBC/upgrade/14_9/schedule @@ -469,4 +469,5 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_1/schedule b/test/JDBC/upgrade/15_1/schedule index ba704815c4..3b93af0f94 100644 --- a/test/JDBC/upgrade/15_1/schedule +++ b/test/JDBC/upgrade/15_1/schedule @@ -442,4 +442,5 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-15_3 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_10/schedule b/test/JDBC/upgrade/15_10/schedule index b73b74cfda..2a07300723 100644 --- a/test/JDBC/upgrade/15_10/schedule +++ b/test/JDBC/upgrade/15_10/schedule @@ -558,3 +558,4 @@ db_ddladmin BABEL-5186 BABEL-2736 smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_11/schedule b/test/JDBC/upgrade/15_11/schedule index 463f37e429..43270d66b7 100644 --- a/test/JDBC/upgrade/15_11/schedule +++ b/test/JDBC/upgrade/15_11/schedule @@ -558,3 +558,4 @@ db_ddladmin BABEL-5186 BABEL-2736 smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index e164028edf..3a56d392dc 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -478,4 +478,5 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-15_3 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_3/schedule b/test/JDBC/upgrade/15_3/schedule index d30d4dccd6..16a276eeea 100644 --- a/test/JDBC/upgrade/15_3/schedule +++ b/test/JDBC/upgrade/15_3/schedule @@ -497,4 +497,5 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index d7bfec90f2..a55985f58d 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -510,4 +510,5 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 smalldatetime_date_cmp-before-15_5-16_1 +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_5/schedule b/test/JDBC/upgrade/15_5/schedule index d085bc4a4c..7c90c390ee 100644 --- a/test/JDBC/upgrade/15_5/schedule +++ b/test/JDBC/upgrade/15_5/schedule @@ -543,4 +543,5 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_6/schedule b/test/JDBC/upgrade/15_6/schedule index 5d73d2bf8a..81a78dcbcf 100644 --- a/test/JDBC/upgrade/15_6/schedule +++ b/test/JDBC/upgrade/15_6/schedule @@ -559,4 +559,5 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_7/schedule b/test/JDBC/upgrade/15_7/schedule index 8f9a091f63..7f7df30b83 100644 --- a/test/JDBC/upgrade/15_7/schedule +++ b/test/JDBC/upgrade/15_7/schedule @@ -567,4 +567,5 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/15_8/schedule b/test/JDBC/upgrade/15_8/schedule index 1b3856fe35..3c1d752bb8 100644 --- a/test/JDBC/upgrade/15_8/schedule +++ b/test/JDBC/upgrade/15_8/schedule @@ -558,4 +558,5 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/16_1/schedule b/test/JDBC/upgrade/16_1/schedule index 08d5dcb10e..1ca7388fa3 100644 --- a/test/JDBC/upgrade/16_1/schedule +++ b/test/JDBC/upgrade/16_1/schedule @@ -552,4 +552,5 @@ datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/16_2/schedule b/test/JDBC/upgrade/16_2/schedule index ad5c7d9ec9..488ef0902c 100644 --- a/test/JDBC/upgrade/16_2/schedule +++ b/test/JDBC/upgrade/16_2/schedule @@ -568,4 +568,5 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/16_3/schedule b/test/JDBC/upgrade/16_3/schedule index 6d2164b7d5..b3bfc2b0e9 100644 --- a/test/JDBC/upgrade/16_3/schedule +++ b/test/JDBC/upgrade/16_3/schedule @@ -572,4 +572,5 @@ securityadmin_role datareader_datawriter BABEL-5186 smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/16_4/schedule b/test/JDBC/upgrade/16_4/schedule index 2cffc4520f..d9bee1e6b2 100644 --- a/test/JDBC/upgrade/16_4/schedule +++ b/test/JDBC/upgrade/16_4/schedule @@ -585,4 +585,5 @@ BABEL-2736-before-16_5 securityadmin_role datareader_datawriter smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/16_6/schedule b/test/JDBC/upgrade/16_6/schedule index a8243aef2a..c3536f0973 100644 --- a/test/JDBC/upgrade/16_6/schedule +++ b/test/JDBC/upgrade/16_6/schedule @@ -588,3 +588,4 @@ dbcreator_role db_securityadmin db_ddladmin smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/16_7/schedule b/test/JDBC/upgrade/16_7/schedule index 5420de502d..bb42e71821 100644 --- a/test/JDBC/upgrade/16_7/schedule +++ b/test/JDBC/upgrade/16_7/schedule @@ -593,3 +593,4 @@ db_securityadmin db_ddladmin smalldatetime_date_cmp db_owner +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/17_2/schedule b/test/JDBC/upgrade/17_2/schedule index 5d54b6103f..6644bb9af9 100644 --- a/test/JDBC/upgrade/17_2/schedule +++ b/test/JDBC/upgrade/17_2/schedule @@ -591,4 +591,5 @@ BABEL-2736 datareader_datawriter db_owner smalldatetime_date_cmp +test_conv_money_to_varchar diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 9bdf0112f1..3c5161256e 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -593,3 +593,4 @@ datareader_datawriter db_owner smalldatetime_date_cmp BABEL-2961 +test_conv_money_to_varchar diff --git a/test/python/expected/sql_validation_framework/expected_drop.out b/test/python/expected/sql_validation_framework/expected_drop.out index 0a4ae9b498..b502710f2d 100644 --- a/test/python/expected/sql_validation_framework/expected_drop.out +++ b/test/python/expected/sql_validation_framework/expected_drop.out @@ -81,6 +81,7 @@ Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file babelfishpg_tsql--4.2.0--4.3.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file babelfishpg_tsql--4.3.0--4.4.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file babelfishpg_tsql--4.4.0--5.0.0.sql +Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file babelfishpg_tsql--5.0.0--5.1.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_table in file babelfishpg_tsql--2.1.0--2.2.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_view in file babelfishpg_tsql--1.0.0--1.1.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_view in file babelfishpg_tsql--2.1.0--2.2.0.sql diff --git a/test/python/expected/upgrade_validation/expected_dependency.out b/test/python/expected/upgrade_validation/expected_dependency.out index 221f5b8c29..d8341bc792 100644 --- a/test/python/expected/upgrade_validation/expected_dependency.out +++ b/test/python/expected/upgrade_validation/expected_dependency.out @@ -192,7 +192,7 @@ Function sys.babelfish_try_cast_floor_bigint(text) Function sys.babelfish_try_conv_date_to_string(text,date,numeric) Function sys.babelfish_try_conv_datetime_to_string(text,text,timestamp without time zone,numeric) Function sys.babelfish_try_conv_float_to_string(text,double precision,numeric) -Function sys.babelfish_try_conv_money_to_string(text,money,numeric) +Function sys.babelfish_try_conv_money_to_string(text,numeric,numeric) Function sys.babelfish_try_conv_string_to_date(text,numeric) Function sys.babelfish_try_conv_string_to_datetime(text,text,numeric) Function sys.babelfish_try_conv_string_to_time(text,text,numeric)