Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create function that returns nothing

People also ask

How do you return nothing from a function?

If you want to return a null function in Python then use the None keyword in the returns statement.

Can a function return nothing in SQL?

Functions can return VOID if there is no useful data to return, as in a SQL DELETE , INSERT , or UPDATE statement.

What does return nothing do in C++?

A void function can returnA void function cannot return any values. But we can use the return statement. It indicates that the function is terminated. It increases the readability of code.

Why does my function return nothing Python?

If we get to the end of any function and we have not explicitly executed any return statement, Python automatically returns the value None. Some functions exists purely to perform actions rather than to calculate and return a result. Such functions are called procedures.


Use RETURNS void like below:

CREATE FUNCTION stamp_user(id int, comment text) RETURNS void AS $$
    #variable_conflict use_variable
    DECLARE
        curtime timestamp := now();
    BEGIN
        UPDATE users SET last_modified = curtime, comment = comment
          WHERE users.id = id;
    END;
$$ LANGUAGE plpgsql;

Functions must always return something, although you can use procedures like

do $$

and start with normal function like

declare
...

but if you still want to do a function just add void after returns.