summaryrefslogtreecommitdiff
path: root/src/pl/plpython/expected/plpython_error.out
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2009-08-12 16:37:26 +0000
committerPeter Eisentraut <peter_e@gmx.net>2009-08-12 16:37:26 +0000
commit9d9848668fd868a4e51f3a3f22c2807ff0e46582 (patch)
tree22b0152fb889ca42d3e4c6ce888d2024b8b8c98b /src/pl/plpython/expected/plpython_error.out
parentef7574eb014b66d99a5e68cc254e7a2282e69a00 (diff)
downloadpostgresql-9d9848668fd868a4e51f3a3f22c2807ff0e46582.tar.gz
Split the plpython regression test into test cases arranged by topic, instead
of the previous monolithic setup-create-run sequence, that was apparently inherited from a previous test infrastructure, but makes working with the tests and adding new ones weird.
Diffstat (limited to 'src/pl/plpython/expected/plpython_error.out')
-rw-r--r--src/pl/plpython/expected/plpython_error.out127
1 files changed, 103 insertions, 24 deletions
diff --git a/src/pl/plpython/expected/plpython_error.out b/src/pl/plpython/expected/plpython_error.out
index ad2d6315ed..8454b05e5e 100644
--- a/src/pl/plpython/expected/plpython_error.out
+++ b/src/pl/plpython/expected/plpython_error.out
@@ -1,45 +1,124 @@
-- test error handling, i forgot to restore Warn_restart in
-- the trigger handler once. the errors and subsequent core dump were
-- interesting.
+/* Flat out syntax error
+ */
+CREATE FUNCTION sql_syntax_error() RETURNS text
+ AS
+'plpy.execute("syntax error")'
+ LANGUAGE plpythonu;
+SELECT sql_syntax_error();
+WARNING: PL/Python: <class 'plpy.SPIError'>: unrecognized error in PLy_spi_execute_query
+CONTEXT: PL/Python function "sql_syntax_error"
+ERROR: syntax error at or near "syntax"
+LINE 1: syntax error
+ ^
+QUERY: syntax error
+CONTEXT: PL/Python function "sql_syntax_error"
+/* check the handling of uncaught python exceptions
+ */
+CREATE FUNCTION exception_index_invalid(text) RETURNS text
+ AS
+'return args[1]'
+ LANGUAGE plpythonu;
+SELECT exception_index_invalid('test');
+ERROR: PL/Python: PL/Python function "exception_index_invalid" failed
+DETAIL: <type 'exceptions.IndexError'>: list index out of range
+CONTEXT: PL/Python function "exception_index_invalid"
+/* check handling of nested exceptions
+ */
+CREATE FUNCTION exception_index_invalid_nested() RETURNS text
+ AS
+'rv = plpy.execute("SELECT test5(''foo'')")
+return rv[0]'
+ LANGUAGE plpythonu;
+SELECT exception_index_invalid_nested();
+WARNING: PL/Python: <class 'plpy.SPIError'>: unrecognized error in PLy_spi_execute_query
+CONTEXT: PL/Python function "exception_index_invalid_nested"
+ERROR: function test5(unknown) does not exist
+LINE 1: SELECT test5('foo')
+ ^
+HINT: No function matches the given name and argument types. You might need to add explicit type casts.
+QUERY: SELECT test5('foo')
+CONTEXT: PL/Python function "exception_index_invalid_nested"
+/* a typo
+ */
+CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text
+ AS
+'if not SD.has_key("plan"):
+ q = "SELECT fname FROM users WHERE lname = $1"
+ SD["plan"] = plpy.prepare(q, [ "test" ])
+rv = plpy.execute(SD["plan"], [ a ])
+if len(rv):
+ return rv[0]["fname"]
+return None
+'
+ LANGUAGE plpythonu;
SELECT invalid_type_uncaught('rick');
-WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
+WARNING: PL/Python: <class 'plpy.SPIError'>: unrecognized error in PLy_spi_prepare
CONTEXT: PL/Python function "invalid_type_uncaught"
ERROR: type "test" does not exist
CONTEXT: PL/Python function "invalid_type_uncaught"
+/* for what it's worth catch the exception generated by
+ * the typo, and return None
+ */
+CREATE FUNCTION invalid_type_caught(a text) RETURNS text
+ AS
+'if not SD.has_key("plan"):
+ q = "SELECT fname FROM users WHERE lname = $1"
+ try:
+ SD["plan"] = plpy.prepare(q, [ "test" ])
+ except plpy.SPIError, ex:
+ plpy.notice(str(ex))
+ return None
+rv = plpy.execute(SD["plan"], [ a ])
+if len(rv):
+ return rv[0]["fname"]
+return None
+'
+ LANGUAGE plpythonu;
SELECT invalid_type_caught('rick');
-WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
+WARNING: PL/Python: <class 'plpy.SPIError'>: unrecognized error in PLy_spi_prepare
CONTEXT: PL/Python function "invalid_type_caught"
ERROR: type "test" does not exist
CONTEXT: PL/Python function "invalid_type_caught"
+/* for what it's worth catch the exception generated by
+ * the typo, and reraise it as a plain error
+ */
+CREATE FUNCTION invalid_type_reraised(a text) RETURNS text
+ AS
+'if not SD.has_key("plan"):
+ q = "SELECT fname FROM users WHERE lname = $1"
+ try:
+ SD["plan"] = plpy.prepare(q, [ "test" ])
+ except plpy.SPIError, ex:
+ plpy.error(str(ex))
+rv = plpy.execute(SD["plan"], [ a ])
+if len(rv):
+ return rv[0]["fname"]
+return None
+'
+ LANGUAGE plpythonu;
SELECT invalid_type_reraised('rick');
-WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
+WARNING: PL/Python: <class 'plpy.SPIError'>: unrecognized error in PLy_spi_prepare
CONTEXT: PL/Python function "invalid_type_reraised"
ERROR: type "test" does not exist
CONTEXT: PL/Python function "invalid_type_reraised"
+/* no typo no messing about
+ */
+CREATE FUNCTION valid_type(a text) RETURNS text
+ AS
+'if not SD.has_key("plan"):
+ SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ])
+rv = plpy.execute(SD["plan"], [ a ])
+if len(rv):
+ return rv[0]["fname"]
+return None
+'
+ LANGUAGE plpythonu;
SELECT valid_type('rick');
valid_type
------------
(1 row)
---
--- Test Unicode error handling.
---
-SELECT unicode_return_error();
-ERROR: PL/Python: could not create string representation of Python object, while creating return value
-DETAIL: exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
-CONTEXT: PL/Python function "unicode_return_error"
-INSERT INTO unicode_test (testvalue) VALUES ('test');
-ERROR: PL/Python: could not compute string representation of Python object, while modifying trigger row
-DETAIL: exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
-CONTEXT: PL/Python function "unicode_trigger_error"
-SELECT unicode_plan_error1();
-WARNING: PL/Python: plpy.Error: unrecognized error in PLy_spi_execute_plan
-CONTEXT: PL/Python function "unicode_plan_error1"
-ERROR: PL/Python: could not execute plan
-DETAIL: exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
-CONTEXT: PL/Python function "unicode_plan_error1"
-SELECT unicode_plan_error2();
-ERROR: PL/Python: could not execute plan
-DETAIL: exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
-CONTEXT: PL/Python function "unicode_plan_error2"