Executar bloco de comando no PostgreSQL

Bloco nomeado

DO $$ 
	<<first_block>>
DECLARE
  film_count integer := 0;
BEGIN
   -- get the number of films
   SELECT COUNT(*) 
   INTO film_count
   FROM "Lancamento";
   -- display a message
   RAISE NOTICE 'The number of films is %', film_count;
END first_block $$;

Bloco anonimo

DO $$ 
DECLARE
  film_count INTEGER := 0;
BEGIN
   -- get the number of films
   SELECT COUNT(*) INTO film_count FROM "Lancamento";
   -- display a message
   RAISE NOTICE 'The number of films is %', film_count;
END
$$;

Deixe um comentário