Function sometime return a null value

Hi All,

I’m running to an issue for my query that sometime returns a null value. Not sure if this a bug or it’s something that I could fix myself. Bellow is a function which is very simple, it takes in an account_id and just return it.

In the select statement, I can see the account number but sometime the get_test() function just return a null value.

– Function

CREATE FUNCTION get_test(
    _account_id SMALLINT UNSIGNED
)
RETURNS SMALLINT UNSIGNED
DETERMINISTIC
BEGIN
    RETURN _account_id;
END//

– Stored Procedure

CREATE PROCEDURE check_post_document()
BEGIN
    SELECT
        get_test(dl.account_id), -- return null
        dl.account_id -- return 123
    FROM document_line dl;
END //

Any help is very much appreciated.

I think your function needs to be NONDETERMINISTIC because the result depends 100% on the input value.

Thanks @matthewb

Will that a go.