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

HTML Several Special Dividing Line Effects

1. Basic lines 2. Special effects (the effects ar...

Detailed explanation of the principles and usage of MySQL stored procedures

This article uses examples to explain the princip...

Vue+openlayer5 method to get the coordinates of the current mouse slide

Preface: How to get the coordinates of the curren...

js native waterfall flow plug-in production

This article shares the specific code of the js n...

New usage of watch and watchEffect in Vue 3

Table of contents 1. New usage of watch 1.1. Watc...

Build a high-availability MySQL cluster with dual VIP

Table of contents 1. Project Description: 2. Proj...

JavaScript Basics: Immediate Execution Function

Table of contents Immediately execute function fo...

Tips for adding favicon to a website: a small icon in front of the URL

The so-called favicon, which is the abbreviation o...

mysql5.7.19 zip detailed installation process and configuration

MySQL v5.7.19 official version (32/64 bit install...

Pure CSS to achieve cool neon light effect (with demo)

I have recently been following the CSS Animation ...

Detailed explanation of Nginx Rewrite usage scenarios and code examples

Nginx Rewrite usage scenarios 1. URL address jump...

Solution to input cursor misalignment in Chrome, Firefox, and IE

Detailed explanation of the misplacement of the in...

Detailed explanation of the use of the <meta> tag in HTML

In the web pages we make, if we want more people ...