1
1
# pg_variables - session variables with various types
2
2
3
- [ ![ Build Status] ( https://travis-ci.org/postgrespro/pg_variables.svg?branch=master )] ( https://travis-ci.org/postgrespro/pg_variables )
4
- [ ![ codecov] ( https://codecov.io/gh/postgrespro/pg_variables/branch/master/graph/badge.svg )] ( https://codecov.io/gh/postgrespro/pg_variables )
5
- [ ![ GitHub license] ( https://img.shields.io/badge/license-PostgreSQL-blue.svg )] ( https://raw.githubusercontent.com/postgrespro/pg_variables/master/README.md )
6
-
7
3
## Introduction
8
4
9
5
The ** pg_variables** module provides functions to work with variables of various
10
6
types. Created variables live only in the current user session.
11
-
12
- Note that the module does ** not support transactions and savepoints by default** . For
13
- example:
14
-
7
+ By default, created variables are not transactional (i.e. they are not affected
8
+ by ` BEGIN ` , ` COMMIT ` or ` ROLLBACK ` statements). This, however, is customizable
9
+ by argument ` is_transactional ` of ` pgv_set() ` :
15
10
``` sql
16
11
SELECT pgv_set(' vars' , ' int1' , 101 );
17
12
BEGIN ;
@@ -26,7 +21,7 @@ SELECT * FROM pgv_list() order by package, name;
26
21
(2 rows)
27
22
```
28
23
29
- But if variable created with flag ** is_transactional** , it does :
24
+ But if variable created with flag ** is_transactional** :
30
25
``` sql
31
26
BEGIN ;
32
27
SELECT pgv_set(' vars' , ' trans_int' , 101 , true);
@@ -255,11 +250,11 @@ You can list packages and variables:
255
250
256
251
``` sql
257
252
SELECT * FROM pgv_list() order by package, name;
258
- package | name
259
- -- -------+------
260
- vars | int1
261
- vars | int2
262
- vars | r1
253
+ package | name | is_transactional
254
+ -- -------+------+------------------
255
+ vars | int1 | f
256
+ vars | int2 | f
257
+ vars | r1 | f
263
258
(3 rows)
264
259
```
265
260
@@ -285,8 +280,8 @@ You can delete all packages and variables:
285
280
SELECT pgv_free();
286
281
```
287
282
288
- If you want variables with support of transactions and savepoints, you should add flag
289
- ` is_transactional = true ` as the last argument in functions ` pgv_set() `
283
+ If you want variables with support of transactions and savepoints, you should
284
+ add flag ` is_transactional = true ` as the last argument in functions ` pgv_set() `
290
285
or ` pgv_insert() ` .
291
286
Following use cases describe behavior of transactional variables:
292
287
``` sql
@@ -317,7 +312,8 @@ SELECT pgv_get('pack', 'var_text', NULL::text);
317
312
before transaction block
318
313
319
314
```
320
- If you create variable after ` BEGIN ` or ` SAVEPOINT ` and than rollback to previous state - variable will not be exist:
315
+ If you create variable after ` BEGIN ` or ` SAVEPOINT ` statements and than rollback
316
+ to previous state - variable will not be exist:
321
317
``` sql
322
318
BEGIN ;
323
319
SAVEPOINT sp1;
@@ -335,7 +331,10 @@ SELECT pgv_get('pack','var_int', NULL::int);
335
331
ERROR: unrecognized variable " var_int"
336
332
COMMIT ;
337
333
```
338
- If you created transactional variable once, you should use flag ` is_transactional ` every time when you want to change variable value by functions ` pgv_set() ` , ` pgv_insert() ` and deprecated setters (i.e. ` pgv_set_int() ` ). If you try to change this option, you'll get an error:
334
+ If you created transactional variable once, you should use flag ` is_transactional `
335
+ every time when you want to change variable value by functions ` pgv_set() ` ,
336
+ ` pgv_insert() ` and deprecated setters (i.e. ` pgv_set_int() ` ). If you try to
337
+ change this option, you'll get an error:
339
338
``` sql
340
339
SELECT pgv_insert(' pack' , ' var_record' , row(123 ::int , ' text' ::text ), true);
341
340
pgv_insert
0 commit comments