|
|
@ -7,7 +7,7 @@ CREATE FUNCTION global_test_one() returns text |
|
|
|
if not GD.has_key("global_test"): |
|
|
|
if not GD.has_key("global_test"): |
|
|
|
GD["global_test"] = "set by global_test_one" |
|
|
|
GD["global_test"] = "set by global_test_one" |
|
|
|
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' |
|
|
|
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION global_test_two() returns text |
|
|
|
CREATE FUNCTION global_test_two() returns text |
|
|
|
AS |
|
|
|
AS |
|
|
@ -16,7 +16,7 @@ CREATE FUNCTION global_test_two() returns text |
|
|
|
if not GD.has_key("global_test"): |
|
|
|
if not GD.has_key("global_test"): |
|
|
|
GD["global_test"] = "set by global_test_two" |
|
|
|
GD["global_test"] = "set by global_test_two" |
|
|
|
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' |
|
|
|
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION static_test() returns int4 |
|
|
|
CREATE FUNCTION static_test() returns int4 |
|
|
@ -27,7 +27,7 @@ else: |
|
|
|
SD["call"] = 1 |
|
|
|
SD["call"] = 1 |
|
|
|
return SD["call"] |
|
|
|
return SD["call"] |
|
|
|
' |
|
|
|
' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
-- import python modules |
|
|
|
-- import python modules |
|
|
|
|
|
|
|
|
|
|
@ -39,7 +39,7 @@ except Exception, ex: |
|
|
|
plpy.notice("import socket failed -- %s" % str(ex)) |
|
|
|
plpy.notice("import socket failed -- %s" % str(ex)) |
|
|
|
return "failed as expected" |
|
|
|
return "failed as expected" |
|
|
|
return "succeeded, that wasn''t supposed to happen"' |
|
|
|
return "succeeded, that wasn''t supposed to happen"' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION import_succeed() returns text |
|
|
|
CREATE FUNCTION import_succeed() returns text |
|
|
@ -63,14 +63,14 @@ except Exception, ex: |
|
|
|
plpy.notice("import failed -- %s" % str(ex)) |
|
|
|
plpy.notice("import failed -- %s" % str(ex)) |
|
|
|
return "failed, that wasn''t supposed to happen" |
|
|
|
return "failed, that wasn''t supposed to happen" |
|
|
|
return "succeeded, as expected"' |
|
|
|
return "succeeded, as expected"' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION import_test_one(text) RETURNS text |
|
|
|
CREATE FUNCTION import_test_one(text) RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
|
'import sha |
|
|
|
'import sha |
|
|
|
digest = sha.new(args[0]) |
|
|
|
digest = sha.new(args[0]) |
|
|
|
return digest.hexdigest()' |
|
|
|
return digest.hexdigest()' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION import_test_two(users) RETURNS text |
|
|
|
CREATE FUNCTION import_test_two(users) RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
@ -78,7 +78,7 @@ CREATE FUNCTION import_test_two(users) RETURNS text |
|
|
|
plain = args[0]["fname"] + args[0]["lname"] |
|
|
|
plain = args[0]["fname"] + args[0]["lname"] |
|
|
|
digest = sha.new(plain); |
|
|
|
digest = sha.new(plain); |
|
|
|
return "sha hash of " + plain + " is " + digest.hexdigest()' |
|
|
|
return "sha hash of " + plain + " is " + digest.hexdigest()' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION argument_test_one(users, text, text) RETURNS text |
|
|
|
CREATE FUNCTION argument_test_one(users, text, text) RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
@ -89,7 +89,7 @@ for key in keys: |
|
|
|
out.append("%s: %s" % (key, args[0][key])) |
|
|
|
out.append("%s: %s" % (key, args[0][key])) |
|
|
|
words = args[1] + " " + args[2] + " => {" + ", ".join(out) + "}" |
|
|
|
words = args[1] + " " + args[2] + " => {" + ", ".join(out) + "}" |
|
|
|
return words' |
|
|
|
return words' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- these triggers are dedicated to HPHC of RI who |
|
|
|
-- these triggers are dedicated to HPHC of RI who |
|
|
@ -110,7 +110,7 @@ if TD["new"]["fname"] == "william": |
|
|
|
TD["new"]["fname"] = TD["args"][0] |
|
|
|
TD["new"]["fname"] = TD["args"][0] |
|
|
|
rv = "MODIFY" |
|
|
|
rv = "MODIFY" |
|
|
|
return rv' |
|
|
|
return rv' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION users_update() returns trigger |
|
|
|
CREATE FUNCTION users_update() returns trigger |
|
|
@ -119,7 +119,7 @@ CREATE FUNCTION users_update() returns trigger |
|
|
|
if TD["old"]["fname"] != TD["new"]["fname"] and TD["old"]["fname"] == TD["args"][0]: |
|
|
|
if TD["old"]["fname"] != TD["new"]["fname"] and TD["old"]["fname"] == TD["args"][0]: |
|
|
|
return "SKIP" |
|
|
|
return "SKIP" |
|
|
|
return None' |
|
|
|
return None' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION users_delete() RETURNS trigger |
|
|
|
CREATE FUNCTION users_delete() RETURNS trigger |
|
|
@ -127,7 +127,7 @@ CREATE FUNCTION users_delete() RETURNS trigger |
|
|
|
'if TD["old"]["fname"] == TD["args"][0]: |
|
|
|
'if TD["old"]["fname"] == TD["args"][0]: |
|
|
|
return "SKIP" |
|
|
|
return "SKIP" |
|
|
|
return None' |
|
|
|
return None' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TRIGGER users_insert_trig BEFORE INSERT ON users FOR EACH ROW |
|
|
|
CREATE TRIGGER users_insert_trig BEFORE INSERT ON users FOR EACH ROW |
|
|
@ -148,19 +148,19 @@ CREATE FUNCTION nested_call_one(text) RETURNS text |
|
|
|
'q = "SELECT nested_call_two(''%s'')" % args[0] |
|
|
|
'q = "SELECT nested_call_two(''%s'')" % args[0] |
|
|
|
r = plpy.execute(q) |
|
|
|
r = plpy.execute(q) |
|
|
|
return r[0]' |
|
|
|
return r[0]' |
|
|
|
LANGUAGE 'plpython' ; |
|
|
|
LANGUAGE plpythonu ; |
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION nested_call_two(text) RETURNS text |
|
|
|
CREATE FUNCTION nested_call_two(text) RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
|
'q = "SELECT nested_call_three(''%s'')" % args[0] |
|
|
|
'q = "SELECT nested_call_three(''%s'')" % args[0] |
|
|
|
r = plpy.execute(q) |
|
|
|
r = plpy.execute(q) |
|
|
|
return r[0]' |
|
|
|
return r[0]' |
|
|
|
LANGUAGE 'plpython' ; |
|
|
|
LANGUAGE plpythonu ; |
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION nested_call_three(text) RETURNS text |
|
|
|
CREATE FUNCTION nested_call_three(text) RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
|
'return args[0]' |
|
|
|
'return args[0]' |
|
|
|
LANGUAGE 'plpython' ; |
|
|
|
LANGUAGE plpythonu ; |
|
|
|
|
|
|
|
|
|
|
|
-- some spi stuff |
|
|
|
-- some spi stuff |
|
|
|
|
|
|
|
|
|
|
@ -176,7 +176,7 @@ except Exception, ex: |
|
|
|
plpy.error(str(ex)) |
|
|
|
plpy.error(str(ex)) |
|
|
|
return None |
|
|
|
return None |
|
|
|
' |
|
|
|
' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION spi_prepared_plan_test_nested(text) RETURNS text |
|
|
|
CREATE FUNCTION spi_prepared_plan_test_nested(text) RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
@ -191,12 +191,12 @@ except Exception, ex: |
|
|
|
plpy.error(str(ex)) |
|
|
|
plpy.error(str(ex)) |
|
|
|
return None |
|
|
|
return None |
|
|
|
' |
|
|
|
' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* really stupid function just to get the module loaded |
|
|
|
/* really stupid function just to get the module loaded |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE 'plpython'; |
|
|
|
CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
/* a typo |
|
|
|
/* a typo |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -210,7 +210,7 @@ if len(rv): |
|
|
|
return rv[0]["fname"] |
|
|
|
return rv[0]["fname"] |
|
|
|
return None |
|
|
|
return None |
|
|
|
' |
|
|
|
' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
/* for what it's worth catch the exception generated by |
|
|
|
/* for what it's worth catch the exception generated by |
|
|
|
* the typo, and return None |
|
|
|
* the typo, and return None |
|
|
@ -229,7 +229,7 @@ if len(rv): |
|
|
|
return rv[0]["fname"] |
|
|
|
return rv[0]["fname"] |
|
|
|
return None |
|
|
|
return None |
|
|
|
' |
|
|
|
' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
/* for what it's worth catch the exception generated by |
|
|
|
/* for what it's worth catch the exception generated by |
|
|
|
* the typo, and reraise it as a plain error |
|
|
|
* the typo, and reraise it as a plain error |
|
|
@ -247,7 +247,7 @@ if len(rv): |
|
|
|
return rv[0]["fname"] |
|
|
|
return rv[0]["fname"] |
|
|
|
return None |
|
|
|
return None |
|
|
|
' |
|
|
|
' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* no typo no messing about |
|
|
|
/* no typo no messing about |
|
|
@ -261,20 +261,20 @@ if len(rv): |
|
|
|
return rv[0]["fname"] |
|
|
|
return rv[0]["fname"] |
|
|
|
return None |
|
|
|
return None |
|
|
|
' |
|
|
|
' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
/* Flat out syntax error |
|
|
|
/* Flat out syntax error |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
CREATE FUNCTION sql_syntax_error() RETURNS text |
|
|
|
CREATE FUNCTION sql_syntax_error() RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
|
'plpy.execute("syntax error")' |
|
|
|
'plpy.execute("syntax error")' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
/* check the handling of uncaught python exceptions |
|
|
|
/* check the handling of uncaught python exceptions |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
CREATE FUNCTION exception_index_invalid(text) RETURNS text |
|
|
|
CREATE FUNCTION exception_index_invalid(text) RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
|
'return args[1]' |
|
|
|
'return args[1]' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
/* check handling of nested exceptions |
|
|
|
/* check handling of nested exceptions |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -282,7 +282,7 @@ CREATE FUNCTION exception_index_invalid_nested() RETURNS text |
|
|
|
AS |
|
|
|
AS |
|
|
|
'rv = plpy.execute("SELECT test5(''foo'')") |
|
|
|
'rv = plpy.execute("SELECT test5(''foo'')") |
|
|
|
return rv[0]' |
|
|
|
return rv[0]' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION join_sequences(sequences) RETURNS text |
|
|
|
CREATE FUNCTION join_sequences(sequences) RETURNS text |
|
|
@ -296,13 +296,13 @@ for r in rv: |
|
|
|
seq = seq + r["sequence"] |
|
|
|
seq = seq + r["sequence"] |
|
|
|
return seq |
|
|
|
return seq |
|
|
|
' |
|
|
|
' |
|
|
|
LANGUAGE 'plpython'; |
|
|
|
LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION read_file(text) RETURNS text AS ' |
|
|
|
CREATE OR REPLACE FUNCTION read_file(text) RETURNS text AS ' |
|
|
|
return open(args[0]).read() |
|
|
|
return open(args[0]).read() |
|
|
|
' LANGUAGE 'plpython'; |
|
|
|
' LANGUAGE plpythonu; |
|
|
|
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION write_file(text,text) RETURNS text AS ' |
|
|
|
CREATE OR REPLACE FUNCTION write_file(text,text) RETURNS text AS ' |
|
|
|
open(args[0],"w").write(args[1]) |
|
|
|
open(args[0],"w").write(args[1]) |
|
|
|
return "Wrote to file: %s" % args[0] |
|
|
|
return "Wrote to file: %s" % args[0] |
|
|
|
' LANGUAGE 'plpython'; |
|
|
|
' LANGUAGE plpythonu; |
|
|
|