"Subtotal" PostgreSQL implements three-dimensional expression function

Source: Internet
Author: User


Create or Replace function decode (p_condition boolean, p_fist_val text, p_last_val text) returns text as$ $declare V_ret_val Text;begin/* Function Description: Analog ternary expression (condition-value1:value2); * Parameter Description: P_condition receive a Boolean expression such as: 1 = 1, 2 > 1, etc.; The latter two values are based on the true and false corresponding return value of p_condition * Implementation principle: P_condition to True return P_fist_val, otherwise return p_last_val */v_ret_val: = null; If True = P_condition then v_ret_val: = P_fist_val; elsif false = P_condition then v_ret_val: = P_last_val; End If; Return v_ret_val;end;$$ language plpgsql;--test Data Select decode (1=2, ' outer ', decode (1=1, ' inter1 ', ' inter2 '));


This article is from the "accumulate Kuibu to thousands of Miles" blog, please be sure to keep this source http://chnjone.blog.51cto.com/4311366/1658846

"Subtotal" PostgreSQL implements three-dimensional expression function

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.