sql脚本函数编写postgresql数据库实现解析
这篇文章主要介绍了sql脚本函数编写postgresql数据库实现解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
postgresql创建Long自增函数
CREATESEQUENCEglobal_id_sequence; CREATEORREPLACEFUNCTIONseq_id(OUTresultbigint)AS$$ DECLARE our_epochbigint:=1314220021721; seq_idbigint; now_millisbigint; --theidofthisDBshard,mustbesetforeach --schemashardyouhave-youcouldpassthisasaparametertoo shard_idint:=1; BEGIN SELECTnextval('global_id_sequence')%1024INTOseq_id; SELECTFLOOR(EXTRACT(EPOCHFROMclock_timestamp())*1000)INTOnow_millis; result:=(now_millis-our_epoch)<<23; result:=result|(shard_id<<10); result:=result|(seq_id); END; $$LANGUAGEPLPGSQL;
创建sql脚本postgresql
dolanguageplpgsql $$ begin updategradesetgrade=90wheresno='20161003'; end $$
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。