zoukankan      html  css  js  c++  java
  • postgresql pg_xlog_location_diff 函数

    pg_xlog_location_diff('','') 这个函数还是比较有用的,在安装9.1时,没有创建,需要手动创建,最好创建在 postgres 数据库下的 public 下。



    CREATE OR REPLACE FUNCTION public.pg_xlog_location_diff(text, text)

     RETURNS numeric
     LANGUAGE plpgsql
    AS $function$
        DECLARE
           offset1 text;
           offset2 text;
           xlog1 text;
           xlog2 text;
           SQL   text;
           diff text;
        BEGIN
           /* Extract the Offset and xlog from input in
              offset and xlog variables */
               
           offset1=split_part($1,'/',2);
             xlog1=split_part($1,'/',1);
           offset2=split_part($2,'/',2);
             xlog2=split_part($2,'/',1);
            
           /* Prepare SQL query for calculation based on following formula
             (FF000000 * xlog + offset) - (FF000000 * xlog + offset)
             which gives value in hexadecimal. Since, hexadecimal calculation is cumbersome
             so convert into decimal and then calculate the difference */
            
           SQL='SELECT (x'''||'FF000000'||'''::bigint * x'''||xlog1||'''::bigint
                                    +  x'''||offset1||'''::bigint)'||'
                    -
                       (x'''||'FF000000'||'''::bigint * x'''||xlog2||'''::bigint
                                    +  x'''||offset2||'''::bigint)';
           EXECUTE SQL into diff;
            
           /* Return the value in numeric by explicit casting  */
            
           RETURN diff::numeric;
        END;
     $function$;
  • 相关阅读:
    CShop Project 082: 获取分页数据模型并传递到页面上
    CShop Project 08: 展示不同类型的商品
    CShop Project 08: 开发商品分类的查询和展示
    119 类和数据类型
    118 对象的绑定方法
    117 对象的属性查找顺序
    116 定制对象独有特征
    115 类和对象
    114 面向对象编程介绍
    113 面向对象程序设计的由来(了解)
  • 原文地址:https://www.cnblogs.com/ctypyb2002/p/9793148.html
Copyright © 2011-2022 走看看