這篇文章主要介紹了sql腳本函數(shù)編寫postgresql數(shù)據(jù)庫實(shí)現(xiàn)解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
postgresql創(chuàng)建Long自增函數(shù)
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;-->
創(chuàng)建sql腳本postgresql
do language plpgsql
$$
begin
update grade set grade = 90 where sno = '20161003';
end
$$
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- PostgreSQL數(shù)據(jù)庫中窗口函數(shù)的語法與使用
- PostgreSQL Node.js實(shí)現(xiàn)函數(shù)計(jì)算方法示例
- PostgreSQL 正則表達(dá)式 常用函數(shù)的總結(jié)
- 深入解讀PostgreSQL中的序列及其相關(guān)函數(shù)的用法
- Postgresql自定義函數(shù)詳解