How to?
For easy example. I have a simple function:
DO LANGUAGE plpgsql $$ DECLARE BEGIN EXECUTE 'SELECT NOW()'; END $$;
How I can return value of "NOW()" or other values from also anonymous function? The function is given as an example I have a more complex function.
PostgreSQL started supporting anonymous blocks with version 9.0. Here “code” can be considered as the body of a function with no parameters, which is going to return void and be parsed and executed one time only (i.e., not going to be stored in database catalog).
PostgreSQL returns a table with one column that holds the array of films. In practice, you often process each individual row before appending it in the function’s result set. The following example illustrates the idea. We have created a function with the similar name get_film (varchar, int) but accepts two parameters:
PL/pgSQL (Procedural Language/PostgreSQL) is a procedural language where you can perform more complex tasks than in SQL—like easy computation—and also make use of loops, functions, and triggers. PL/pgSQL code is managed in blocks (block structured code), into which anonymous blocks, functions, and procedures are organized.
insert ... returning ... produces a result set that contains columns referenced in the returning clause. In a PL/pgSQL block that result set must be dealt with somehow. You have three options:
DO LANGUAGE plpgsql $$ DECLARE BEGIN execute ' create temporary table t as SELECT NOW() '; END $$; select * from t;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With