You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contrib/pg_variables/README.md
+74-16Lines changed: 74 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,23 @@
5
5
The**pg_variables** module provides functions to work with variables of various
6
6
types. Created variables live only in the current user session.
7
7
8
+
Note that the module does**not support transactions and savepoints**. For
9
+
example:
10
+
11
+
```sql
12
+
SELECT pgv_set_int('vars','int1',101);
13
+
BEGIN;
14
+
SELECT pgv_set_int('vars','int2',102);
15
+
ROLLBACK;
16
+
17
+
SELECT*FROM pgv_list()order by package, name;
18
+
package | name
19
+
---------+------
20
+
vars | int1
21
+
vars | int2
22
+
(2 rows)
23
+
```
24
+
8
25
##License
9
26
10
27
This module available under the same license as
@@ -22,6 +39,35 @@ Typical installation procedure may look like this:
22
39
23
40
##Module functions
24
41
42
+
The functions provided by the**pg_variables** module are shown in the tables
43
+
below. The module supports the following scalar and record types.
44
+
45
+
To use**pgv_get_()** functions required package and variable must exists. It is
46
+
necessary to set variable with**pgv_set_()** functions to use**pgv_get_()**
47
+
functions.
48
+
49
+
If a package does not exists you will get the following error:
50
+
51
+
```sql
52
+
SELECT pgv_get_int('vars','int1');
53
+
ERROR: unrecognized package"vars"
54
+
```
55
+
56
+
If a variable does not exists you will get the following error:
57
+
58
+
```sql
59
+
SELECT pgv_get_int('vars','int1');
60
+
ERROR: unrecognized variable"int1"
61
+
```
62
+
63
+
**pgv_get_()** functions check the variable type. If the variable type does not
64
+
match with the function type the error will be raised:
65
+
66
+
```sql
67
+
SELECT pgv_get_text('vars','int1');
68
+
ERROR: variable"int1" requires"integer" value
69
+
```
70
+
25
71
###Integer variables
26
72
27
73
Function | Returns
@@ -73,25 +119,37 @@ Function | Returns
73
119
74
120
###Records
75
121
76
-
Function | Returns
77
-
-------- | -------
78
-
`pgv_insert(package text, name text, r record)` |`void`
79
-
`pgv_update(package text, name text, r record)` |`boolean`
80
-
`pgv_delete(package text, name text, value anynonarray)` |`boolean`
81
-
`pgv_select(package text, name text)` |`set of record`
82
-
`pgv_select(package text, name text, value anynonarray)` |`record`
83
-
`pgv_select(package text, name text, value anyarray)` |`set of record`
122
+
The following functions are provided by the module to work with collections of
123
+
record types.
124
+
125
+
To use**pgv_update()**,**pgv_delete()** and**pgv_select()** functions
126
+
required package and variable must exists. Otherwise the error will be raised.
127
+
It is necessary to set variable with**pgv_insert()** function to use these
128
+
functions.
129
+
130
+
**pgv_update()**,**pgv_delete()** and**pgv_select()** functions check the
131
+
variable type. If the variable type does not**record** type the error will be
132
+
raised.
133
+
134
+
Function | Returns | Description
135
+
-------- | ------- | -----------
136
+
`pgv_insert(package text, name text, r record)` |`void` | Inserts a record to the variable collection. If package and variable do not exists they will be created. The first column of**r** will be a primary key. If exists a record with the same primary key the error will be raised. If this variable collection has other structure the error will be raised.
137
+
`pgv_update(package text, name text, r record)` |`boolean` | Updates a record with the corresponding primary key (the first column of**r** is a primary key). Returns**true** if a record was found. If this variable collection has other structure the error will be raised.
138
+
`pgv_delete(package text, name text, value anynonarray)` |`boolean` | Deletes a record with the corresponding primary key (the first column of**r** is a primary key). Returns**true** if a record was found.
139
+
`pgv_select(package text, name text)` |`set of record` | Returns the variable collection records.
140
+
`pgv_select(package text, name text, value anynonarray)` |`record` | Returns the record with the corresponding primary key (the first column of**r** is a primary key).
141
+
`pgv_select(package text, name text, value anyarray)` |`set of record` | Returns the variable collection records with the corresponding primary keys (the first column of**r** is a primary key).
`pgv_exists(package text, name text)` |`bool` | Returns**true** if package and variable exists.
148
+
`pgv_remove(package text, name text)` |`void` | Removes the variable with the corresponding name. Required package and variable must exists, otherwise the error will be raised.
149
+
`pgv_remove(package text)` |`void` | Removes the package and all package variables with the corresponding name. Required package must exists, otherwise the error will be raised.
150
+
`pgv_free()` |`void` | Removes all packages and variables.
151
+
`pgv_list()` |`table(package text, name text)` | Returns set of records of assigned packages and variables.
152
+
`pgv_stats()` |`table(package text, used_memory bigint)` | Returns list of assigned packages and used memory in bytes.
95
153
96
154
Note that**pgv_stats()** works only with the PostgreSQL 9.6 and newer.