共計 797 個字符,預(yù)計需要花費 2 分鐘才能閱讀完成。
自動寫代碼機器人,免費開通
這篇文章主要介紹了 sql 腳本函數(shù)編寫 postgresql 數(shù)據(jù)庫實現(xiàn)解析, 文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值, 需要的朋友可以參考下
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);
$$ 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';
$$
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持丸趣 TV。
向 AI 問一下細節(jié)
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完
發(fā)表至: 數(shù)據(jù)庫
2023-12-18