mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-22 09:43:23 +02:00
Remove the code in plpgsql that suppressed the innermost line of CONTEXT for messages emitted by RAISE commands. That was never more than a quick backwards-compatibility hack, and it's pretty silly in cases where the RAISE is nested in several levels of function. What's more, it violated our design theory that verbosity of error reports should be controlled on the client side not the server side. To alleviate the resulting noise increase, introduce a feature in libpq and psql whereby the CONTEXT field of messages can be suppressed, either always or only for non-error messages. Printing CONTEXT for errors only is now their default behavior. The actual code changes here are pretty small, but the effects on the regression test outputs are widespread. I had to edit some of the alternative expected outputs by hand; hopefully the buildfarm will soon find anything I fat-fingered. In passing, fix up (again) the output line counts in psql's various help displays. Add some commentary about how to verify them. Pavel Stehule, reviewed by Petr Jelínek, Jeevan Chalke, and others
127 lines
2.9 KiB
Plaintext
127 lines
2.9 KiB
Plaintext
CREATE EXTENSION plpython2u;
|
|
CREATE EXTENSION hstore_plpython2u;
|
|
-- test hstore -> python
|
|
CREATE FUNCTION test1(val hstore) RETURNS int
|
|
LANGUAGE plpythonu
|
|
TRANSFORM FOR TYPE hstore
|
|
AS $$
|
|
assert isinstance(val, dict)
|
|
i = list(val.items())
|
|
i.sort()
|
|
plpy.info(i)
|
|
return len(val)
|
|
$$;
|
|
SELECT test1('aa=>bb, cc=>NULL'::hstore);
|
|
INFO: [('aa', 'bb'), ('cc', None)]
|
|
test1
|
|
-------
|
|
2
|
|
(1 row)
|
|
|
|
-- the same with the versioned language name
|
|
CREATE FUNCTION test1n(val hstore) RETURNS int
|
|
LANGUAGE plpython2u
|
|
TRANSFORM FOR TYPE hstore
|
|
AS $$
|
|
assert isinstance(val, dict)
|
|
i = list(val.items())
|
|
i.sort()
|
|
plpy.info(i)
|
|
return len(val)
|
|
$$;
|
|
SELECT test1n('aa=>bb, cc=>NULL'::hstore);
|
|
INFO: [('aa', 'bb'), ('cc', None)]
|
|
test1n
|
|
--------
|
|
2
|
|
(1 row)
|
|
|
|
-- test hstore[] -> python
|
|
CREATE FUNCTION test1arr(val hstore[]) RETURNS int
|
|
LANGUAGE plpythonu
|
|
TRANSFORM FOR TYPE hstore
|
|
AS $$
|
|
assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}])
|
|
return len(val)
|
|
$$;
|
|
SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
|
|
test1arr
|
|
----------
|
|
2
|
|
(1 row)
|
|
|
|
-- test python -> hstore
|
|
CREATE FUNCTION test2() RETURNS hstore
|
|
LANGUAGE plpythonu
|
|
TRANSFORM FOR TYPE hstore
|
|
AS $$
|
|
val = {'a': 1, 'b': 'boo', 'c': None}
|
|
return val
|
|
$$;
|
|
SELECT test2();
|
|
test2
|
|
---------------------------------
|
|
"a"=>"1", "b"=>"boo", "c"=>NULL
|
|
(1 row)
|
|
|
|
-- test python -> hstore[]
|
|
CREATE FUNCTION test2arr() RETURNS hstore[]
|
|
LANGUAGE plpythonu
|
|
TRANSFORM FOR TYPE hstore
|
|
AS $$
|
|
val = [{'a': 1, 'b': 'boo', 'c': None}, {'d': 2}]
|
|
return val
|
|
$$;
|
|
SELECT test2arr();
|
|
test2arr
|
|
--------------------------------------------------------------
|
|
{"\"a\"=>\"1\", \"b\"=>\"boo\", \"c\"=>NULL","\"d\"=>\"2\""}
|
|
(1 row)
|
|
|
|
-- test as part of prepare/execute
|
|
CREATE FUNCTION test3() RETURNS void
|
|
LANGUAGE plpythonu
|
|
TRANSFORM FOR TYPE hstore
|
|
AS $$
|
|
rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1")
|
|
assert(rv[0]["col1"] == {'aa': 'bb', 'cc': None})
|
|
|
|
val = {'a': 1, 'b': 'boo', 'c': None}
|
|
plan = plpy.prepare("SELECT $1::text AS col1", ["hstore"])
|
|
rv = plpy.execute(plan, [val])
|
|
assert(rv[0]["col1"] == '"a"=>"1", "b"=>"boo", "c"=>NULL')
|
|
$$;
|
|
SELECT test3();
|
|
test3
|
|
-------
|
|
|
|
(1 row)
|
|
|
|
-- test trigger
|
|
CREATE TABLE test1 (a int, b hstore);
|
|
INSERT INTO test1 VALUES (1, 'aa=>bb, cc=>NULL');
|
|
SELECT * FROM test1;
|
|
a | b
|
|
---+------------------------
|
|
1 | "aa"=>"bb", "cc"=>NULL
|
|
(1 row)
|
|
|
|
CREATE FUNCTION test4() RETURNS trigger
|
|
LANGUAGE plpythonu
|
|
TRANSFORM FOR TYPE hstore
|
|
AS $$
|
|
assert(TD["new"] == {'a': 1, 'b': {'aa': 'bb', 'cc': None}})
|
|
if TD["new"]["a"] == 1:
|
|
TD["new"]["b"] = {'a': 1, 'b': 'boo', 'c': None}
|
|
|
|
return "MODIFY"
|
|
$$;
|
|
CREATE TRIGGER test4 BEFORE UPDATE ON test1 FOR EACH ROW EXECUTE PROCEDURE test4();
|
|
UPDATE test1 SET a = a;
|
|
SELECT * FROM test1;
|
|
a | b
|
|
---+---------------------------------
|
|
1 | "a"=>"1", "b"=>"boo", "c"=>NULL
|
|
(1 row)
|
|
|