Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

310
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda