Thread: proposal: plpgsql: special comments that will be part of AST

proposal: plpgsql: special comments that will be part of AST

From
Pavel Stehule
Date:
Hi,

As an author of plpgsql_check, I permanently have to try to solve genetic problems with the necessity of external information for successful static validation.

create or replace function foo(tablename text)
returns void as $$
declare r record;
begin
  execute format('select * from %I', tablename) into r;
  raise notice '%', r.x;
end;
$$ language plpgsql;

On this very simple code it is not possible to make static validation. Currently, there is no way to push some extra information to source code, that helps with static analysis, but doesn't break evaluation without plpgsql_check, and doesn't do some significant slowdown.

I proposed Ada language pragmas, but it was rejected.

I implemented fake pragmas in plpgsql_check via arguments of special function

PERFORM plpgsql_check_pragma('plpgsql_check: off');

It is working, but it looks bizarre, and it requires a fake function plpgsql_check_pragma on production, so it is a little bit a dirty solution.

Now, I have another proposal(s).

a) Can we invite new syntax for comments, that will be stored in AST like a non executing statement?

some like:

//* plpgsql_check: OFF *//
RAISE NOTICE '%', r.x

or second design

b) can we introduce some flag for plpgsql_parser, that allows storing comments in AST (it will not be default).

so  "-- plpgsql_check: OFF " will work for my purpose, and I don't need any special syntax.

Comments, notes?

Pavel

Re: proposal: plpgsql: special comments that will be part of AST

From
Pavel Stehule
Date:
Hi



some like:

//* plpgsql_check: OFF *//
RAISE NOTICE '%', r.x

or second design

b) can we introduce some flag for plpgsql_parser, that allows storing comments in AST (it will not be default).

so  "-- plpgsql_check: OFF " will work for my purpose, and I don't need any special syntax.

Comments, notes?

When I started work on PoC I found that it was not a good idea.  Comments can be everywhere, but it is not possible to enhance plpgsql's gram in this way. So this is not an way

Regards

Pavel