PostgreSQL notes stored procedure insert data cyclically

Source: Internet
Author: User

 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;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.