plpgsql_check update

93 views
Skip to first unread message

Pavel Stěhule

unread,
Aug 17, 2014, 3:51:54 PM8/17/14
to postgresql-ext...@googlegroups.com
Hi

today I commit a significant plpgsql_check update.

Now it checks a assignment and a return statement much more carefully:

create or replace function f1()
returns table(ax numeric, bx numeric) as $$
begin
  return query select * from tabret;
  return;
end;
$$ language plpgsql;
select * from plpgsql_check_function('f1()', performance_warnings := true);
                              plpgsql_check_function
-----------------------------------------------------------------------------------
 error:42804:3:RETURN QUERY:structure of query does not match function result type
 Detail: Returned type integer does not match expected type numeric in column 1.
(2 rows)

create or replace function f1() returns void as $$
declare
intval integer;
begin
  intval := null; -- ok
  intval := 1; -- OK
  intval := '1'; -- OK
  intval := text '1'; -- not OK
  intval := current_date; -- not OK

  select 1 into intval; -- OK
  select '1' into intval; -- OK
  select text '1' into intval; -- not OK
end
$$ language plpgsql;
select * from plpgsql_check_function('f1()', performance_warnings := true);
                                    plpgsql_check_function
----------------------------------------------------------------------------------------------
 performance:42804:7:assignment:target variable has different type then expression result
 Detail: assign "unknown" value to "integer" variable
 Hint: Hidden casting can be a performance issue.
 warning:42804:8:assignment:target variable has different type then expression result
 Detail: assign "text" value to "integer" variable
 Hint: The input expression type does not have an assignment cast to the target type.
 warning:42804:9:assignment:target variable has different type then expression result
 Detail: assign "date" value to "integer" variable
 Hint: There are no possible explicit coercion between those types, possibly bug!
 performance:42804:12:SQL statement:target variable has different type then expression result
 Detail: assign "unknown" value to "integer" variable
 Hint: Hidden casting can be a performance issue.
 warning:42804:13:SQL statement:target variable has different type then expression result
 Detail: assign "text" value to "integer" variable
 Hint: The input expression type does not have an assignment cast to the target type.
(15 rows)


Please, check it

https://github.com/okbob/plpgsql_check

Regards

Pavel

Pavel Stěhule

unread,
Aug 24, 2014, 12:30:38 AM8/24/14
to postgresql-ext...@googlegroups.com


Dne neděle, 17. srpna 2014 21:51:54 UTC+2 Pavel Stěhule napsal(a):


I did a few but important bugfixes last two days,

please, update from master if you use 0.9

Regards

Pavel
Reply all
Reply to author
Forward
0 new messages