hi all
i have written a function in postgres. here is my code
this function runs fine when r_temp and r_temp1 is not null. if either one of them is null then it should return the respective value and exit the function. but my problem is the function continues even it has to exit. how to exit the query when the condition is satisfied and exit the function too. if r_temp is null, then it should exit the function, it should not run the next query for r_temp1. but now it is running for both the queries.
i need help
plz anyone can help me. any help is appreciated.
i have written a function in postgres. here is my code
Code:
CREATE OR REPLACE FUNCTION fn_new("varchar", float8, "varchar", "varchar", date, "varchar")
RETURNS "varchar" AS
'
declare
r_temp varchar;
r_temp1 varchar;
a varchar;
Begin
SELECT field1 INTO r_temp FROM tbl_a;
IF r_temp IS NULL or r_temp='''' THEN
begin
RETURN 1;
exit;
END;
END IF;
SELECT field2 INTO r_temp1 FROM tbl_b WHERE field3=$1;
IF r_temp1 IS NULL OR r_temp1='''' THEN
begin
RETURN 2;
exit;
end;
END IF;
insert into tbl_c values
($4,$5,r_temp,$2,$3,$6,\'D\',\'Null\');
insert into tbl_c values
($4,$5,r_temp1,$2,$3,$6,\'C\',\'Null\');
return a;
end'
LANGUAGE 'plpgsql' VOLATILE;
i need help
plz anyone can help me. any help is appreciated.
Comment