1
1
CREATE FUNCTION elog_test() RETURNS void
2
2
AS $$
3
- plpy.debug('debug', detail = 'some detail')
4
- plpy.log('log', detail = 'some detail')
5
- plpy.info('info', detail = 'some detail')
3
+ plpy.debug('debug', detail= 'some detail')
4
+ plpy.log('log', detail= 'some detail')
5
+ plpy.info('info', detail= 'some detail')
6
6
plpy.info()
7
- plpy.info('the question', detail = 42);
7
+ plpy.info('the question', detail= 42);
8
8
plpy.info('This is message text.',
9
- detail = 'This is detail text',
10
- hint = 'This is hint text.',
11
- sqlstate = 'XX000',
12
- schema_name = 'any info about schema',
13
- table_name = 'any info about table',
14
- column_name = 'any info about column',
15
- datatype_name = 'any info about datatype',
16
- constraint_name = 'any info about constraint')
17
- plpy.notice('notice', detail = 'some detail')
18
- plpy.warning('warning', detail = 'some detail')
19
- plpy.error('stop on error', detail = 'some detail', hint = 'some hint')
9
+ detail= 'This is detail text',
10
+ hint= 'This is hint text.',
11
+ sqlstate= 'XX000',
12
+ schema_name= 'any info about schema',
13
+ table_name= 'any info about table',
14
+ column_name= 'any info about column',
15
+ datatype_name= 'any info about datatype',
16
+ constraint_name= 'any info about constraint')
17
+ plpy.notice('notice', detail= 'some detail')
18
+ plpy.warning('warning', detail= 'some detail')
19
+ plpy.error('stop on error', detail= 'some detail', hint= 'some hint')
20
20
$$ LANGUAGE plpythonu;
21
21
SELECT elog_test();
22
22
INFO: info
@@ -36,92 +36,98 @@ DETAIL: some detail
36
36
HINT: some hint
37
37
CONTEXT: Traceback (most recent call last):
38
38
PL/Python function "elog_test", line 18, in <module>
39
- plpy.error('stop on error', detail = 'some detail', hint = 'some hint')
39
+ plpy.error('stop on error', detail= 'some detail', hint= 'some hint')
40
40
PL/Python function "elog_test"
41
- do $$ plpy.info('other types', detail = (10,20)) $$ LANGUAGE plpythonu;
41
+ DO $$ plpy.info('other types', detail= (10, 20)) $$ LANGUAGE plpythonu;
42
42
INFO: other types
43
43
DETAIL: (10, 20)
44
- do $$
44
+ DO $$
45
45
import time;
46
46
from datetime import date
47
- plpy.info('other types', detail = date(2016,2, 26))
47
+ plpy.info('other types', detail= date(2016, 2, 26))
48
48
$$ LANGUAGE plpythonu;
49
49
INFO: other types
50
50
DETAIL: 2016-02-26
51
- do $$
51
+ DO $$
52
52
basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
53
- plpy.info('other types', detail = basket)
53
+ plpy.info('other types', detail= basket)
54
54
$$ LANGUAGE plpythonu;
55
55
INFO: other types
56
56
DETAIL: ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
57
57
-- should fail
58
- do $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpythonu;
58
+ DO $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpythonu;
59
59
ERROR: invalid SQLSTATE code
60
60
CONTEXT: PL/Python anonymous code block
61
- do $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpythonu;
61
+ DO $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpythonu;
62
62
ERROR: 'blabla' is an invalid keyword argument for this function
63
63
CONTEXT: PL/Python anonymous code block
64
- do $$ plpy.info('first message', message='second message') $$ LANGUAGE plpythonu;
64
+ DO $$ plpy.info('first message', message='second message') $$ LANGUAGE plpythonu;
65
65
ERROR: the message is already specified
66
66
CONTEXT: PL/Python anonymous code block
67
- do $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpythonu;
67
+ DO $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpythonu;
68
68
ERROR: the message is already specified
69
69
CONTEXT: PL/Python anonymous code block
70
70
-- raise exception in python, handle exception in plgsql
71
71
CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT NULL, _hint text DEFAULT NULL,
72
- _sqlstate text DEFAULT NULL,
73
- _schema_name text DEFAULT NULL, _table_name text DEFAULT NULL, _column_name text DEFAULT NULL,
74
- _datatype_name text DEFAULT NULL, _constraint_name text DEFAULT NULL)
72
+ _sqlstate text DEFAULT NULL,
73
+ _schema_name text DEFAULT NULL,
74
+ _table_name text DEFAULT NULL,
75
+ _column_name text DEFAULT NULL,
76
+ _datatype_name text DEFAULT NULL,
77
+ _constraint_name text DEFAULT NULL)
75
78
RETURNS void AS $$
76
- kwargs = { "message":_message, "detail":_detail, "hint":_hint,
77
- "sqlstate":_sqlstate, "schema_name":_schema_name, "table_name":_table_name,
78
- "column_name":_column_name, "datatype_name":_datatype_name, "constraint_name":_constraint_name }
79
+ kwargs = {
80
+ "message": _message, "detail": _detail, "hint": _hint,
81
+ "sqlstate": _sqlstate, "schema_name": _schema_name, "table_name": _table_name,
82
+ "column_name": _column_name, "datatype_name": _datatype_name,
83
+ "constraint_name": _constraint_name
84
+ }
79
85
# ignore None values - should work on Python2.3
80
86
dict = {}
81
87
for k in kwargs:
82
- if kwargs[k] is not None:
83
- dict[k] = kwargs[k]
88
+ if kwargs[k] is not None:
89
+ dict[k] = kwargs[k]
84
90
plpy.error(**dict)
85
91
$$ LANGUAGE plpythonu;
86
92
SELECT raise_exception('hello', 'world');
87
93
ERROR: plpy.Error: hello
88
94
DETAIL: world
89
95
CONTEXT: Traceback (most recent call last):
90
- PL/Python function "raise_exception", line 10 , in <module>
96
+ PL/Python function "raise_exception", line 13 , in <module>
91
97
plpy.error(**dict)
92
98
PL/Python function "raise_exception"
93
99
SELECT raise_exception('message text', 'detail text', _sqlstate => 'YY333');
94
100
ERROR: plpy.Error: message text
95
101
DETAIL: detail text
96
102
CONTEXT: Traceback (most recent call last):
97
- PL/Python function "raise_exception", line 10 , in <module>
103
+ PL/Python function "raise_exception", line 13 , in <module>
98
104
plpy.error(**dict)
99
105
PL/Python function "raise_exception"
100
106
SELECT raise_exception(_message => 'message text',
101
- _detail => 'detail text',
102
- _hint => 'hint text',
103
- _sqlstate => 'XX555',
104
- _schema_name => 'schema text',
105
- _table_name => 'table text',
106
- _column_name => 'column text',
107
- _datatype_name => 'datatype text',
108
- _constraint_name => 'constraint text');
107
+ _detail => 'detail text',
108
+ _hint => 'hint text',
109
+ _sqlstate => 'XX555',
110
+ _schema_name => 'schema text',
111
+ _table_name => 'table text',
112
+ _column_name => 'column text',
113
+ _datatype_name => 'datatype text',
114
+ _constraint_name => 'constraint text');
109
115
ERROR: plpy.Error: message text
110
116
DETAIL: detail text
111
117
HINT: hint text
112
118
CONTEXT: Traceback (most recent call last):
113
- PL/Python function "raise_exception", line 10 , in <module>
119
+ PL/Python function "raise_exception", line 13 , in <module>
114
120
plpy.error(**dict)
115
121
PL/Python function "raise_exception"
116
122
SELECT raise_exception(_message => 'message text',
117
- _hint => 'hint text',
118
- _schema_name => 'schema text',
119
- _column_name => 'column text',
120
- _constraint_name => 'constraint text');
123
+ _hint => 'hint text',
124
+ _schema_name => 'schema text',
125
+ _column_name => 'column text',
126
+ _constraint_name => 'constraint text');
121
127
ERROR: plpy.Error: message text
122
128
HINT: hint text
123
129
CONTEXT: Traceback (most recent call last):
124
- PL/Python function "raise_exception", line 10 , in <module>
130
+ PL/Python function "raise_exception", line 13 , in <module>
125
131
plpy.error(**dict)
126
132
PL/Python function "raise_exception"
127
133
DO $$
@@ -157,34 +163,34 @@ BEGIN
157
163
__datatype_name = PG_DATATYPE_NAME,
158
164
__constraint_name = CONSTRAINT_NAME;
159
165
RAISE NOTICE 'handled exception'
160
- USING DETAIL = format('message:(%s), detail:(%s), hint: (%s), sqlstate: (%s), '
161
- 'schema_name:(%s), table_name:(%s), column_name:(%s), datatype_name:(%s), constraint_name:(%s)',
162
- __message, __detail, __hint, __sqlstate, __schema_name,
163
- __table_name, __column_name, __datatype_name, __constraint_name);
166
+ USING DETAIL = format('message:(%s), detail:(%s), hint: (%s), sqlstate: (%s), '
167
+ 'schema_name:(%s), table_name:(%s), column_name:(%s), datatype_name:(%s), constraint_name:(%s)',
168
+ __message, __detail, __hint, __sqlstate, __schema_name,
169
+ __table_name, __column_name, __datatype_name, __constraint_name);
164
170
END;
165
171
END;
166
172
$$;
167
173
NOTICE: handled exception
168
174
DETAIL: message:(plpy.Error: message text), detail:(detail text), hint: (hint text), sqlstate: (XX555), schema_name:(schema text), table_name:(table text), column_name:(column text), datatype_name:(datatype text), constraint_name:(constraint text)
169
- -- the displayed context is different between Python2 and Python3,
170
- -- but that's not important for this test
175
+ -- The displayed context is different between Python2 and Python3,
176
+ -- but that's not important for this test.
171
177
\set SHOW_CONTEXT never
172
- do $$
178
+ DO $$
173
179
try:
174
- plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
180
+ plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
175
181
except Exception, e:
176
- plpy.info(e.spidata)
177
- raise e
182
+ plpy.info(e.spidata)
183
+ raise e
178
184
$$ LANGUAGE plpythonu;
179
185
INFO: (119577128, None, 'some hint', None, 0, None, 'users_tab', None, 'user_type', None)
180
186
ERROR: plpy.SPIError: plpy.Error: my message
181
187
HINT: some hint
182
- do $$
188
+ DO $$
183
189
try:
184
- plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type')
190
+ plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type')
185
191
except Exception, e:
186
- plpy.info('sqlstate: %s, hint: %s, table_name: %s, datatype_name: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
187
- raise e
192
+ plpy.info('sqlstate: %s, hint: %s, table_name: %s, datatype_name: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
193
+ raise e
188
194
$$ LANGUAGE plpythonu;
189
195
INFO: sqlstate: XX987, hint: some hint, table_name: users_tab, datatype_name: user_type
190
196
ERROR: plpy.Error: my message
0 commit comments