1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-26 01:22:12 +03:00
Files
postgres/src/pl/plpython/sql/plpython_import.sql
Peter Eisentraut 45223fd9ce Modernize Python exception syntax in tests
Change the exception syntax used in the tests to use the more current

    except Exception as ex:

rather than the old

    except Exception, ex:

Since support for Python <2.6 has been removed, all supported versions
now support the new style, and we can save one step in the Python 3
compatibility conversion.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/98b69261-298c-13d2-f34d-836fd9c29b21%402ndquadrant.com
2020-01-08 22:47:22 +01:00

69 lines
1.4 KiB
SQL

-- import python modules
CREATE FUNCTION import_fail() returns text
AS
'try:
import foosocket
except ImportError:
return "failed as expected"
return "succeeded, that wasn''t supposed to happen"'
LANGUAGE plpythonu;
CREATE FUNCTION import_succeed() returns text
AS
'try:
import array
import bisect
import calendar
import cmath
import errno
import math
import operator
import random
import re
import string
import time
except Exception as ex:
plpy.notice("import failed -- %s" % str(ex))
return "failed, that wasn''t supposed to happen"
return "succeeded, as expected"'
LANGUAGE plpythonu;
CREATE FUNCTION import_test_one(p text) RETURNS text
AS
'try:
import hashlib
digest = hashlib.sha1(p.encode("ascii"))
except ImportError:
import sha
digest = sha.new(p)
return digest.hexdigest()'
LANGUAGE plpythonu;
CREATE FUNCTION import_test_two(u users) RETURNS text
AS
'plain = u["fname"] + u["lname"]
try:
import hashlib
digest = hashlib.sha1(plain.encode("ascii"))
except ImportError:
import sha
digest = sha.new(plain);
return "sha hash of " + plain + " is " + digest.hexdigest()'
LANGUAGE plpythonu;
-- import python modules
--
SELECT import_fail();
SELECT import_succeed();
-- test import and simple argument handling
--
SELECT import_test_one('sha hash of this string');
-- test import and tuple argument handling
--
select import_test_two(users) from users where fname = 'willem';