Skip to content

PostgreSQL procedual

GradedJestRisk edited this page Feb 14, 2024 · 1 revision

Documentation

Postgresql can natively call:

  • pg/plsql
  • perl
  • python
Documentation With extension:
  • Java
  • JavaScript
  • shell

Table of Contents

Shell

https://github.com/petere/plsh

Can't access database

JavaScript

Can access database

Install

Docker

DockerHub image

Here

Custom image

Start with https://github.com/clkao/docker-postgres-plv8/blob/master/12-2/Dockerfile

docker build -t plv8:12-2 .

Native Documentation

CREATE EXTENSION plv8;
DO $$plv8.elog(NOTICE, "Hello, world!"); $$ LANGUAGE plv8;

Access DB

https://plv8.github.io/#database-access-via-spi

Track row change

Crazy idea

Install

npm install plv8-git

psql -c "
  create extension if not exists plv8;
  select plv8_version();
"

psql -f node_modules/plv8-git/queries/create-git-functions.sql

Test

create table test_table(
  id int,
  text text,
  git json
);

create trigger test_table_git_track_trigger
  before insert or update
  on test_table for each row
  execute procedure git_track();


insert into test_table(id, text)
values(1, 'item 1 old content');

update test_table
set text = 'item 1 new content'
where id = 1;

select git_log(git)
from test_table
where id = 1