Page 1 sur 1

Procédures

Posté : lun. 4 déc. 2017 11:56
par Phil
Il était déjà possible de créer des fonctions retournant VOID mais PostgreSQL 11 accepte à présent la syntaxe CREATE PROCEDURE, démonstration :

Code : Tout sélectionner

 select version();
                                          version
--------------------------------------------------------------------------------------------
 PostgreSQL 11devel on x86_64-pc-linux-gnu, compiled by gcc (Debian 7.2.0-16) 7.2.0, 64-bit
(1 ligne)


start transaction;
START TRANSACTION

create table all_times(cu timestamp, st timestamp, cl timestamp);
CREATE TABLE

CREATE PROCEDURE pg_temp.insert_times()
LANGUAGE SQL
AS $$
INSERT INTO all_times(cu, st, cl) VALUES (current_timestamp, statement_timestamp(), clock_timestamp());
$$;
CREATE PROCEDURE

CALL pg_temp.insert_times();
CALL

CALL pg_temp.insert_times();
CALL

CALL pg_temp.insert_times();
CALL

select * from all_times;
             cu             |             st             |             cl
----------------------------+----------------------------+----------------------------
 2017-12-04 10:50:10.534769 | 2017-12-04 10:50:32.398735 | 2017-12-04 10:50:32.399498
 2017-12-04 10:50:10.534769 | 2017-12-04 10:50:37.670564 | 2017-12-04 10:50:37.670967
 2017-12-04 10:50:10.534769 | 2017-12-04 10:50:43.103117 | 2017-12-04 10:50:43.103508
(3 lignes)


rollback;
ROLLBACK

\q
Article à ce sujet : https://pgphil.ovh/procedure_11_devel_01.php

Procédures

Posté : dim. 17 juin 2018 13:04
par Phil
Pouvoir faire commit ou rollback simplement en pl/pgsql avec PostgreSQL 11, démonstration autour des transactions embarquées dans la page consacrée aux procédures : https://pgphil.ovh/procedure_11_beta_01.php