You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1) Create not-null domain with specified default value (the type doesn't matter: varchar, integer, ...):
create domain intdef$ as integer default 0 not null
2) Create recursive procedure with variable of not-null domain either local or returned:
-- sample with returned variable
create procedure a(cnt integer)
returns (ret intdef$)
as
begin
-- ret = 0;
while (cnt>0) do begin
cnt = cnt-1;
for select ret from a(:cnt) into ret do suspend;
end
suspend;
end
or
-- sample with local variable
create procedure a(cnt integer)
returns (ret intdef$)
as
declare x intdef$;
begin
-- x = 0;
while (cnt>0) do begin
cnt = cnt-1;
for select ret from a(:cnt) into ret do begin ret=x; suspend; end
end
ret=x;
suspend;
end
3) Call the procedure:
select * from a(4)
It fails with: The insert failed because a column definition includes validation constraints. Validation error for variable RET, value '*** null ***'.
4) When assignments of variables (ret = 0 and x = 0 respectively) are uncommented, both procedures work properly returning 16 zeros.
Seems like variables in procedures called recursively don't get their initial values from their domains and remain nulls. This is unlike any other variable (declared in non-recursive procedures). For example, this procedure normally returns zero:
create procedure a(cnt integer)
returns (ret intdef$)
as
begin
suspend;
end
Submitted by: Viner Mihail (mviner)
1) Create not-null domain with specified default value (the type doesn't matter: varchar, integer, ...):
create domain intdef$ as integer default 0 not null
2) Create recursive procedure with variable of not-null domain either local or returned:
-- sample with returned variable
create procedure a(cnt integer)
returns (ret intdef$)
as
begin
-- ret = 0;
while (cnt>0) do begin
cnt = cnt-1;
for select ret from a(:cnt) into ret do suspend;
end
suspend;
end
or
-- sample with local variable
create procedure a(cnt integer)
returns (ret intdef$)
as
declare x intdef$;
begin
-- x = 0;
while (cnt>0) do begin
cnt = cnt-1;
for select ret from a(:cnt) into ret do begin ret=x; suspend; end
end
ret=x;
suspend;
end
3) Call the procedure:
select * from a(4)
It fails with: The insert failed because a column definition includes validation constraints. Validation error for variable RET, value '*** null ***'.
4) When assignments of variables (ret = 0 and x = 0 respectively) are uncommented, both procedures work properly returning 16 zeros.
Seems like variables in procedures called recursively don't get their initial values from their domains and remain nulls. This is unlike any other variable (declared in non-recursive procedures). For example, this procedure normally returns zero:
create procedure a(cnt integer)
returns (ret intdef$)
as
begin
suspend;
end
Commits: e3cdddf 06328e6
The text was updated successfully, but these errors were encountered: