Create or replace function autogenfeature_function () returns text as <br/>$ <br/> declare <br/> B _count int; <br/> beacon_id int; <br/> _ total int; <br/> begin <br/> select count (*) into B _count from Beacon; <br/> _ Total: = B _count; <br/> while B _count> 0 loop <br/> select PID into beacon_id from Beacon limit 1 offset B _count-1; <br/> insert into workfeature (typeid, typeactid, beaconid, creatorid, createdate, remark) values (7, 7, beacon_id, 1, now (), 'Automated aerial mark inspection job'); <br/> B _count: = B _count-1; <br/> end loop; <br/> return 'added in total' | _ Total | 'inspection jobs for air paces'; <br/> end; <br/>$ $ <br/> language plpgsql;
Small Example of postgresql Stored Procedure
Create or replace function increment (I integer) RETURNS integer AS $ <br/> BEGIN <br/> RETURN I + 1; <br/> END; <br/> $ LANGUAGE plpgsql; <br/>
Create function add (integer, integer) RETURNS integer <br/> AS 'select $1 + $2; '<br/> language SQL <br/> IMMUTABLE <br/> RETURNS NULL ON NULL INPUT;