PostgreSQL Stored Procedures/functions

Source: Internet
Author: User
Tags postgresql postgresql function

1. Useful Links

PostgreSQL Common small functions

some string manipulation functions of the PostgreSQL database

function called in PostgreSQL function

PostgreSQL Learning Manual (Functions and Operators < two >)

A simple way to get started with PostgreSQL stored procedures

2. Building a block environment (execution environment)

 Do language Plpgsql $$  declare  begin  ...  End $$;  

Such as

  Dolanguage Plpgsql $$ declare today date:=Now ();           Yesterday date; Beginday Date:='2012-12-12';    Val date; Iint; I_str varchar ( -); Begin--calls in the stored procedure need to use the Perform keyword perform initsfunction (); if(Today is NULL) then RAISE NOTICE'today is null' ; ElseRAISE NOTICE'today is not NULL' ; Endif; end;$$;

3. Create a stored procedure

Create or Replace function initstandardcheckindays () returnsvoid   as$body $ declare today date;        Beginday date;        Val date; Iint; Begin Today:=current_date; ifNot EXISTS (Select 1  fromstandardcheckindays) then Beginday:='2012-12-12'; ELSEIF (Not EXISTS (Select 1  fromStandardcheckindayswhereStcheckindate=today)) Then Beginday= (SelectMax (Stcheckindate) fromstandardcheckindays); Endif; if(Beginday is  NULL) then RAISE NOTICE'the standard sign-in table for the day's data already exists'     ; ElseRAISE NOTICE'the data for the day does not exist in the standard registration table'  ; RAISE NOTICE'initialized or 30 years later! Data for the day does not exist in the standard sign-in table'  ;  forIinch 1.. -* -Loop val:= Beginday +i;                Insert into Standardcheckindays (stcheckindate) values (val); RAISE NOTICE' %', Val;        End Loop; Endif; End; $body $ language plpgsql;
Select ' Current Date: ' | | To_char (now (),'yyyy-mm-dd HH24:MI:SS.MS');

PostgreSQL Stored Procedures/functions

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.