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

Use non-root users to execute script operations in docker containers

After the application is containerized, when the ...

Two ways to install the Linux subsystem in Windows 10 (with pictures and text)

Windows 10 now supports Linux subsystem, saying g...

Implementation of installing and uninstalling CUDA and CUDNN in Ubuntu

Table of contents Preface Install the graphics dr...

Case study of dynamic data binding of this.$set in Vue

I feel that the explanation of this.$set on the I...

How to configure https for nginx in docker

Websites without https support will gradually be ...

mysql5.5 installation graphic tutorial under win7

MySQL installation is relatively simple, usually ...

JS+AJAX realizes the linkage of province, city and district drop-down lists

This article shares the specific code of JS+AJAX ...

Implementing circular scrolling list function based on Vue

Note: You need to give the parent container a hei...

Analysis of MySQL lock wait and deadlock problems

Table of contents Preface: 1. Understand lock wai...

Screen command and usage in Linux

Screen Introduction Screen is a free software dev...

How to change mysql password under Centos

1. Modify MySQL login settings: # vim /etc/my.cnf...

Detailed explanation of react setState

Table of contents Is setState synchronous or asyn...

Detailed installation tutorial of mysql 5.7 under CentOS 6 and 7

You always need data for development. As a server...

Example code for converting Mysql query result set into JSON data

Mysql converts query result set into JSON data Pr...