Procedures are widely used in development environments as they work as a kind of methods in the database and its main functions to optimize the processing of complex commands and also reuse code.

In PostgreSQL, the procedures are created using the following syntax:

CREATE OR REPLACE FUNCTION [Procedure Name]

RETURN [Type of return]

$$

DECLARE

[Variables]

BEGIN

[Command]

END

$$

In the declaration of a procedure the instructions CREATE and ALTER are used simultaneously so there are no problems as duplicate inclusion, for example, which would cause execution errors.

In PostgreSQL, unlike other DBMS, you must always tell the kind of returns that the procedure will take. The return is the most common setof referred queries in database, this return type is mainly used in the construction of reports as shown below:

CREATE OR REPLACE FUNCTION productList()

RETURN setof vproduct

$$

BEGIN

SELECT Name, Price FROM product

END

$$

Note that in the above procedure we are listing the field name and price from product table, this information will be returned through the variable declared as vprodutos return.

Importantly, any variable can be returned in a procedure according to the need of implementation.

database-postgre-sql

PostgreSQL growing web development environments and so it is very important to understand how the database works. Learn the advantages of working with PostgreSQL and PHP on our official site.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.