
CREATE TABLE plausible_rscale_adjustments
(
    var1ndigits integer,
    var2ndigits integer,
    var1dscale integer,
    var2dscale integer,
    rscale_adjustment integer
);

\copy plausible_rscale_adjustments from plausible_rscale_adjustments.csv with csv;


CREATE TABLE test_numeric_mul_rscale
(
    var1 numeric,
    var2 numeric,
    rscale_adjustment integer,
    expected numeric
);

SELECT setseed(0);

INSERT INTO test_numeric_mul_rscale
    (var1, var2, rscale_adjustment, expected)
SELECT
    var1,
    var2,
    rscale_adjustment,
    numeric_mul_rscale(var1, var2, rscale_adjustment)
FROM
(
    SELECT
        rscale_adjustment,
        round(random(
            format('1%s',repeat('0',(var1ndigits-1)*4-1))::numeric,
            format('%s',repeat('9',var1ndigits*4))::numeric
        ) / 10::numeric^var1dscale, var1dscale) AS var1,
        round(random(
            format('1%s',repeat('0',(var2ndigits-1)*4-1))::numeric,
            format('%s',repeat('9',var2ndigits*4))::numeric
        ) / 10::numeric^var2dscale, var2dscale) AS var2
    FROM
        plausible_rscale_adjustments,
        generate_series(1, 10000)
) AS q;

\copy test_numeric_mul_rscale to test_numeric_mul_rscale.dump;
