PostgreSQL
 SQL >> Base de Dados >  >> RDS >> PostgreSQL

Como Criar Sua Primeira Função no PostgreSQL

Funções encapsulam operações e podem ser chamadas em consultas.

Exemplo

CREATE OR REPLACE FUNCTION total()
RETURNS integer AS $total$
DECLARE
  total integer;
BEGIN
  SELECT COUNT(*) INTO total FROM sales;
  RETURN total;
END;
$total$ LANGUAGE plpgsql;

Chamando

SELECT total();