Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!