sql script function to write postgresql database to implement parsing

sql script function to write postgresql database to implement parsing

This article mainly introduces the sql script function to write postgresql database to implement parsing. The example code in the article is very detailed and has a certain reference value for everyone's study or work. Friends in need can refer to it.

postgresql creates a Long auto-increment function

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;-->

Create sql script postgresql

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

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Syntax and usage of window functions in PostgreSQL database
  • Example of implementing function calculation method in PostgreSQL Node.js
  • Summary of common functions of PostgreSQL regular expressions
  • In-depth analysis of the usage of sequences and related functions in PostgreSQL
  • Detailed explanation of Postgresql custom functions

<<:  Solution to blank page after Vue packaging

>>:  Use of Linux cal command

Recommend

Implementation of MySQL joint index (composite index)

Joint Index The definition of the joint index in ...

How to expand Linux swap memory

Swap memory mainly means that when the physical m...

Introduction to cloud native technology kubernetes (K8S)

Table of contents 01 What is Kubernetes? 02 The d...

A must-read career plan for web design practitioners

Original article, please indicate the author and ...

Mysql database index interview questions (basic programmer skills)

Table of contents introduction Indexing principle...

In-depth understanding of umask in new linux file permission settings

Preface The origin is a question 1: If your umask...

This article takes you into the world of js data types and data structures

Table of contents 1. What is dynamic typing? 2. D...

Example code of vue icon selector

Source: http://www.ruoyi.vip/ import Vue from ...

Let's talk about the performance of MySQL's COUNT(*)

Preface Basically, programmers in the workplace u...

Thirty HTML coding guidelines for beginners

1. Always close HTML tags In the source code of p...

How to use VUE and Canvas to implement a Thunder Fighter typing game

Today we are going to implement a Thunder Fighter...

Implementation of installing and uninstalling CUDA and CUDNN in Ubuntu

Table of contents Preface Install the graphics dr...

Use tomcat to deploy SpringBoot war package in centos environment

Prepare war package 1. Prepare the existing Sprin...