aws / pg_tle

Framework for building trusted language extensions for PostgreSQL
Apache License 2.0
337 stars 31 forks source link

Debugging failed extension creation #247

Open ajrajkumar opened 1 year ago

ajrajkumar commented 1 year ago

Describe the problem

Currently we use pgtle.install_extension to create the extension code which is part of the code block. The block could contain multiple statements to create multiple objects. If the extension creation failed due to any syntax error, it would be difficult to debug since the error does not have any reference or line number

Here the sample code to reproduce it

pg_tle | 1.1.1 | pgtle | Trusted Language Extensions for PostgreSQL

SELECT pgtle.install_extension( 'get_count', '1.0.0', 'Sample count function', $pgtle$ Create or replace function get_count(len_from int, len_to int) returns int language plpgsql as $$ declare film_count integer; begin film_count = len_from + len_to;
return film_count; end; $$

grant execute on function get_count(int, int) to public;

$pgtle$ );

postgres=> \i get_count.sql install_extension

t (1 row)

postgres=> create extension get_count; ERROR: syntax error at or near "grant"

I intentionally did not add ; after the $$ of the function and it failed to create the extension. But the error message is not easy to debug as some extension may have may grant statements ( or similar)