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

冬天,洁白的雪花慢慢地飘落下来,落到这里,飘到那里,我们仿佛置身于童话般的雪白世界。在苍茫的大海上,狂风卷集着乌云。在乌云和大海描写大海的散文之间,海燕像黑色的闪电,在高傲的飞翔。

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

postgresql创建Long自增函数

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

do language plpgsql
$$
begin
update grade set grade = 90 where sno = '20161003';
end
$$

以上就是sql脚本函数编写postgresql数据库如何实现解析。生命并不是你活了多少日子,而是你记住了多少日子,你要使你过的每一天,都值得记忆。更多关于sql脚本函数编写postgresql数据库如何实现解析请关注haodaima.com其它相关文章!

您可能有感兴趣的文章
centos7 mysql5.7主从同步配置

centos7安装MySQL教程

达梦数据库DM8表空间管理之删除表空间

达梦数据库DM8表空间管理之创建表空间

国产达梦数据库常用SQL语句(上)