Database Reference
In-Depth Information
multi line
comment
style
*/
The following is an example of a PL/pgSQL function that explains about the usage
of comments. You can see how comments increase the readability and make it
comprehensible for anyone going through the block. Comments will surely help
you recall the purpose of the code if you revisit it after a long time.:
warehouse_db=# CREATE OR REPLACE FUNCTION concat (text, text)
--
--This function will concatenate the two strings.
--
/* pipe characters are used to
Concatenate
the strings */
RETURNS text AS $$
BEGIN
RETURN $1 || ' ' || $2;
END;
$$ LANGUAGE plpgsql;
The following statement shows the result:
warehouse_db=# SELECT concat('ware', 'house');
concat
------------
ware house
(1 row)
Declaring variables in PL/pgSQL
We know variables are used to store data. PL/pgSQL allows you to use variables
to achieve this. Each variable is thus used in the lifetime of a block and must be
declared within the DECLARE block starting with the DECLARE keyword.
Let's take a few lines from the getRecords() function we used earlier, as follows:
CREATE OR REPLACE FUNCTION getRecords()
RETURNS integer AS $$
Declare
total INTEGER;
 
Search WWH ::




Custom Search