Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

311
Visualizações
Any way to make Postgres stricter when creating functions?

We started to use Postgres much more recently, having moved from SQL Server. I've noticed that Postgres parser/compiler allows creation of functions that (it seems to me) can be rejected at creation time.

One example of what I'm talking about is select statements in plpgsql blocks:

create or replace function test() returns void as $$
begin
    select * from pg_database;
end; 
$$ language plpgsql;

This function fails at runtime with "query has no destination for result data". Why would this error not be caught at function creation time? Is there any case when using select without 'return' in plpgsql block is allowed?

The other type of errors that are not always caught at compile time is type mismatch errors between a declared return type and actual type of the value. These are caught in simple cases, but start to make it to runtime in more complicated functions. I suspect there's some limitations in Postgres type inference/analysis, is there any additional information on this available?

tldr: Is there any way to make Postgres parser/compiler fail more on function creation?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Is there any way to make Postgres parser/compiler fail more on function creation?

That's the purpose of the plpgsql_check extension. It won't prevent the function to be created, though.

test=# create extension plpgsql_check;
CREATE EXTENSION

test=# create or replace function test() returns void as $$
begin
    select * from pg_database;
end; 
$$ language plpgsql;

test=# select * from plpgsql_check_function('test');
                        plpgsql_check_function                        
----------------------------------------------------------------------
 error:42601:3:SQL statement:query has no destination for result data
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda