@@ -72,194 +72,3 @@ CONTEXT: Traceback (most recent call last):
7272 PL/Python function "elog_test_basic", line 10, in <module>
7373 plpy.error('error')
7474PL/Python function "elog_test_basic"
75- CREATE FUNCTION elog_test() RETURNS void
76- AS $$
77- plpy.debug('debug', detail = 'some detail')
78- plpy.log('log', detail = 'some detail')
79- plpy.info('info', detail = 'some detail')
80- plpy.info()
81- plpy.info('the question', detail = 42);
82- plpy.info('This is message text.',
83- detail = 'This is detail text',
84- hint = 'This is hint text.',
85- sqlstate = 'XX000',
86- schema = 'any info about schema',
87- table = 'any info about table',
88- column = 'any info about column',
89- datatype = 'any info about datatype',
90- constraint = 'any info about constraint')
91- plpy.notice('notice', detail = 'some detail')
92- plpy.warning('warning', detail = 'some detail')
93- plpy.error('stop on error', detail = 'some detail', hint = 'some hint')
94- $$ LANGUAGE plpythonu;
95- SELECT elog_test();
96- INFO: info
97- DETAIL: some detail
98- INFO: ()
99- INFO: the question
100- DETAIL: 42
101- INFO: This is message text.
102- DETAIL: This is detail text
103- HINT: This is hint text.
104- NOTICE: notice
105- DETAIL: some detail
106- WARNING: warning
107- DETAIL: some detail
108- ERROR: plpy.Error: stop on error
109- DETAIL: some detail
110- HINT: some hint
111- CONTEXT: Traceback (most recent call last):
112- PL/Python function "elog_test", line 18, in <module>
113- plpy.error('stop on error', detail = 'some detail', hint = 'some hint')
114- PL/Python function "elog_test"
115- do $$ plpy.info('other types', detail = (10,20)) $$ LANGUAGE plpythonu;
116- INFO: other types
117- DETAIL: (10, 20)
118- do $$
119- import time;
120- from datetime import date
121- plpy.info('other types', detail = date(2016,2,26))
122- $$ LANGUAGE plpythonu;
123- INFO: other types
124- DETAIL: 2016-02-26
125- do $$
126- basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
127- plpy.info('other types', detail = basket)
128- $$ LANGUAGE plpythonu;
129- INFO: other types
130- DETAIL: ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
131- -- should fail
132- do $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpythonu;
133- ERROR: invalid SQLSTATE code
134- CONTEXT: PL/Python anonymous code block
135- do $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpythonu;
136- ERROR: 'blabla' is an invalid keyword argument for this function
137- CONTEXT: PL/Python anonymous code block
138- do $$ plpy.info('first message', message='second message') $$ LANGUAGE plpythonu;
139- ERROR: the message is already specified
140- CONTEXT: PL/Python anonymous code block
141- do $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpythonu;
142- ERROR: the message is already specified
143- CONTEXT: PL/Python anonymous code block
144- -- raise exception in python, handle exception in plgsql
145- CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT NULL, _hint text DEFAULT NULL,
146- _sqlstate text DEFAULT NULL,
147- _schema text DEFAULT NULL, _table text DEFAULT NULL, _column text DEFAULT NULL,
148- _datatype text DEFAULT NULL, _constraint text DEFAULT NULL)
149- RETURNS void AS $$
150- kwargs = { "message":_message, "detail":_detail, "hint":_hint,
151- "sqlstate":_sqlstate, "schema":_schema, "table":_table,
152- "column":_column, "datatype":_datatype, "constraint":_constraint }
153- # ignore None values - should work on Python2.3
154- dict = {}
155- for k in kwargs:
156- if kwargs[k] is not None:
157- dict[k] = kwargs[k]
158- plpy.error(**dict)
159- $$ LANGUAGE plpythonu;
160- SELECT raise_exception('hello', 'world');
161- ERROR: plpy.Error: hello
162- DETAIL: world
163- CONTEXT: Traceback (most recent call last):
164- PL/Python function "raise_exception", line 10, in <module>
165- plpy.error(**dict)
166- PL/Python function "raise_exception"
167- SELECT raise_exception('message text', 'detail text', _sqlstate => 'YY333');
168- ERROR: plpy.Error: message text
169- DETAIL: detail text
170- CONTEXT: Traceback (most recent call last):
171- PL/Python function "raise_exception", line 10, in <module>
172- plpy.error(**dict)
173- PL/Python function "raise_exception"
174- SELECT raise_exception(_message => 'message text',
175- _detail => 'detail text',
176- _hint => 'hint text',
177- _sqlstate => 'XX555',
178- _schema => 'schema text',
179- _table => 'table text',
180- _column => 'column text',
181- _datatype => 'datatype text',
182- _constraint => 'constraint text');
183- ERROR: plpy.Error: message text
184- DETAIL: detail text
185- HINT: hint text
186- CONTEXT: Traceback (most recent call last):
187- PL/Python function "raise_exception", line 10, in <module>
188- plpy.error(**dict)
189- PL/Python function "raise_exception"
190- SELECT raise_exception(_message => 'message text',
191- _hint => 'hint text',
192- _schema => 'schema text',
193- _column => 'column text',
194- _constraint => 'constraint text');
195- ERROR: plpy.Error: message text
196- HINT: hint text
197- CONTEXT: Traceback (most recent call last):
198- PL/Python function "raise_exception", line 10, in <module>
199- plpy.error(**dict)
200- PL/Python function "raise_exception"
201- DO $$
202- DECLARE
203- __message text;
204- __detail text;
205- __hint text;
206- __sqlstate text;
207- __schema_name text;
208- __table_name text;
209- __column_name text;
210- __datatype text;
211- __constraint text;
212- BEGIN
213- BEGIN
214- PERFORM raise_exception(_message => 'message text',
215- _detail => 'detail text',
216- _hint => 'hint text',
217- _sqlstate => 'XX555',
218- _schema => 'schema text',
219- _table => 'table text',
220- _column => 'column text',
221- _datatype => 'datatype text',
222- _constraint => 'constraint text');
223- EXCEPTION WHEN SQLSTATE 'XX555' THEN
224- GET STACKED DIAGNOSTICS __message = MESSAGE_TEXT,
225- __detail = PG_EXCEPTION_DETAIL,
226- __hint = PG_EXCEPTION_HINT,
227- __sqlstate = RETURNED_SQLSTATE,
228- __schema_name = SCHEMA_NAME,
229- __table_name = TABLE_NAME,
230- __column_name = COLUMN_NAME,
231- __datatype = PG_DATATYPE_NAME,
232- __constraint = CONSTRAINT_NAME;
233- RAISE NOTICE 'handled exception'
234- USING DETAIL = format('message:(%s), detail:(%s), hint: (%s), sqlstate: (%s), '
235- 'schema:(%s), table:(%s), column:(%s), datatype:(%s), constraint:(%s)',
236- __message, __detail, __hint, __sqlstate, __schema_name,
237- __table_name, __column_name, __datatype, __constraint);
238- END;
239- END;
240- $$;
241- NOTICE: handled exception
242- DETAIL: message:(plpy.Error: message text), detail:(detail text), hint: (hint text), sqlstate: (XX555), schema:(schema text), table:(table text), column:(column text), datatype:(datatype text), constraint:(constraint text)
243- -- the displayed context is different between Python2 and Python3,
244- -- but that's not important for this test
245- \set SHOW_CONTEXT never
246- do $$
247- try:
248- plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table=> 'users_tab', _datatype => 'user_type')")
249- except Exception, e:
250- plpy.info(e.spidata)
251- raise e
252- $$ LANGUAGE plpythonu;
253- INFO: (119577128, None, 'some hint', None, 0, None, 'users_tab', None, 'user_type', None)
254- ERROR: plpy.SPIError: plpy.Error: my message
255- HINT: some hint
256- do $$
257- try:
258- plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table = 'users_tab', datatype = 'user_type')
259- except Exception, e:
260- plpy.info('sqlstate: %s, hint: %s, tablename: %s, datatype: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
261- raise e
262- $$ LANGUAGE plpythonu;
263- INFO: sqlstate: XX987, hint: some hint, tablename: users_tab, datatype: user_type
264- ERROR: plpy.Error: my message
265- HINT: some hint
0 commit comments