sql脚本函数编写postgresql数据库实现解析

吾爱主题 阅读:172 2024-04-05 14:22:59 评论:0

这篇文章主要介绍了sql脚本函数编写postgresql数据库实现解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

postgresql创建Long自增函数

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 CREATE SEQUENCE global_id_sequence;   CREATE OR REPLACE FUNCTION seq_id( OUT result bigint ) AS $$ DECLARE    our_epoch bigint := 1314220021721;    seq_id bigint ;    now_millis bigint ;    -- the id of this DB shard, must be set for each    -- schema shard you have - you could pass this as a parameter too    shard_id int := 1; BEGIN    SELECT nextval( 'global_id_sequence' ) % 1024 INTO seq_id;      SELECT FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000) INTO now_millis;    result := (now_millis - our_epoch) << 23;    result := result | (shard_id << 10);    result := result | (seq_id); END ; $$ LANGUAGE PLPGSQL;   <! --alter function seq_id(out bigint) owner to postgres;-->

创建sql脚本postgresql

?
1 2 3 4 5 6 do language plpgsql $$ begin update grade set grade = 90 where sno = '20161003' ; end $$

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.cnblogs.com/ltspring/p/11508636.html

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容