Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
0a269db9
Commit
0a269db9
authored
May 26, 2006
by
Andrew Dunstan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parent
777f72cd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
3 deletions
+107
-3
doc/src/sgml/plpython.sgml
doc/src/sgml/plpython.sgml
+4
-1
src/pl/plpython/expected/plpython_function.out
src/pl/plpython/expected/plpython_function.out
+55
-0
src/pl/plpython/plpython.c
src/pl/plpython/plpython.c
+17
-2
src/pl/plpython/sql/plpython_function.sql
src/pl/plpython/sql/plpython_function.sql
+31
-0
No files found.
doc/src/sgml/plpython.sgml
View file @
0a269db9
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.
29 2005/05/20 01:52:25 neilc
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.
30 2006/05/26 19:23:09 adunstan
Exp $ -->
<chapter id="plpython">
<chapter id="plpython">
<title>PL/Python - Python Procedural Language</title>
<title>PL/Python - Python Procedural Language</title>
...
@@ -123,6 +123,9 @@ def __plpython_procedure_myfunc_23456():
...
@@ -123,6 +123,9 @@ def __plpython_procedure_myfunc_23456():
<literal>AFTER</>, and <literal>UNKNOWN</>.
<literal>AFTER</>, and <literal>UNKNOWN</>.
<literal>TD["level"]</> contains one of <literal>ROW</>,
<literal>TD["level"]</> contains one of <literal>ROW</>,
<literal>STATEMENT</>, and <literal>UNKNOWN</>.
<literal>STATEMENT</>, and <literal>UNKNOWN</>.
<literal>TD["name"]</> contains the trigger name,
<literal>TD["table_name"]</> contains the name of the table on which the trigger occurred,
<literal>TD["table_schema"]</> contains the schema of the table on which the trigger occurred,
<literal>TD["name"]</> contains the trigger name, and
<literal>TD["name"]</> contains the trigger name, and
<literal>TD["relid"]</> contains the OID of the table on
<literal>TD["relid"]</> contains the OID of the table on
which the trigger occurred. If the <command>CREATE TRIGGER</> command
which the trigger occurred. If the <command>CREATE TRIGGER</> command
...
...
src/pl/plpython/expected/plpython_function.out
View file @
0a269db9
...
@@ -115,6 +115,61 @@ CREATE TRIGGER users_update_trig BEFORE UPDATE ON users FOR EACH ROW
...
@@ -115,6 +115,61 @@ CREATE TRIGGER users_update_trig BEFORE UPDATE ON users FOR EACH ROW
EXECUTE PROCEDURE users_update ('willem');
EXECUTE PROCEDURE users_update ('willem');
CREATE TRIGGER users_delete_trig BEFORE DELETE ON users FOR EACH ROW
CREATE TRIGGER users_delete_trig BEFORE DELETE ON users FOR EACH ROW
EXECUTE PROCEDURE users_delete ('willem');
EXECUTE PROCEDURE users_delete ('willem');
-- dump trigger data
CREATE TABLE trigger_test
(i int, v text );
CREATE FUNCTION trigger_data() returns trigger language plpythonu as $$
if TD.has_key('relid'):
TD['relid'] = "bogus:12345"
for key in sorted(TD.keys()):
val = TD[key]
plpy.notice("TD[" + key + "] => " + str(val))
return None
$$;
CREATE TRIGGER show_trigger_data_trig
BEFORE INSERT OR UPDATE OR DELETE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE trigger_data(23,'skidoo');
insert into trigger_test values(1,'insert');
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: ('TD[event] => INSERT',)
NOTICE: ('TD[level] => ROW',)
NOTICE: ('TD[name] => show_trigger_data_trig',)
NOTICE: ("TD[new] => {'i': 1, 'v': 'insert'}",)
NOTICE: ('TD[old] => None',)
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: ('TD[table_schema] => public',)
NOTICE: ('TD[when] => BEFORE',)
update trigger_test set v = 'update' where i = 1;
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: ('TD[event] => UPDATE',)
NOTICE: ('TD[level] => ROW',)
NOTICE: ('TD[name] => show_trigger_data_trig',)
NOTICE: ("TD[new] => {'i': 1, 'v': 'update'}",)
NOTICE: ("TD[old] => {'i': 1, 'v': 'insert'}",)
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: ('TD[table_schema] => public',)
NOTICE: ('TD[when] => BEFORE',)
delete from trigger_test;
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: ('TD[event] => DELETE',)
NOTICE: ('TD[level] => ROW',)
NOTICE: ('TD[name] => show_trigger_data_trig',)
NOTICE: ('TD[new] => None',)
NOTICE: ("TD[old] => {'i': 1, 'v': 'update'}",)
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: ('TD[table_schema] => public',)
NOTICE: ('TD[when] => BEFORE',)
DROP TRIGGER show_trigger_data_trig on trigger_test;
DROP FUNCTION trigger_data();
-- nested calls
-- nested calls
--
--
CREATE FUNCTION nested_call_one(text) RETURNS text
CREATE FUNCTION nested_call_one(text) RETURNS text
...
...
src/pl/plpython/plpython.c
View file @
0a269db9
/**********************************************************************
/**********************************************************************
* plpython.c - python as a procedural language for PostgreSQL
* plpython.c - python as a procedural language for PostgreSQL
*
*
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.
79 2006/04/27 14:18:07 momji
an Exp $
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.
80 2006/05/26 19:23:09 adunst
an Exp $
*
*
*********************************************************************
*********************************************************************
*/
*/
...
@@ -560,7 +560,9 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc, HeapTuple *
...
@@ -560,7 +560,9 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc, HeapTuple *
*
pltevent
,
*
pltevent
,
*
pltwhen
,
*
pltwhen
,
*
pltlevel
,
*
pltlevel
,
*
pltrelid
;
*
pltrelid
,
*
plttablename
,
*
plttableschema
;
PyObject
*
pltargs
,
PyObject
*
pltargs
,
*
pytnew
,
*
pytnew
,
*
pytold
;
*
pytold
;
...
@@ -584,6 +586,19 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc, HeapTuple *
...
@@ -584,6 +586,19 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc, HeapTuple *
Py_DECREF
(
pltrelid
);
Py_DECREF
(
pltrelid
);
pfree
(
stroid
);
pfree
(
stroid
);
stroid
=
SPI_getrelname
(
tdata
->
tg_relation
);
plttablename
=
PyString_FromString
(
stroid
);
PyDict_SetItemString
(
pltdata
,
"table_name"
,
plttablename
);
Py_DECREF
(
plttablename
);
pfree
(
stroid
);
stroid
=
SPI_getnspname
(
tdata
->
tg_relation
);
plttableschema
=
PyString_FromString
(
stroid
);
PyDict_SetItemString
(
pltdata
,
"table_schema"
,
plttableschema
);
Py_DECREF
(
plttableschema
);
pfree
(
stroid
);
if
(
TRIGGER_FIRED_BEFORE
(
tdata
->
tg_event
))
if
(
TRIGGER_FIRED_BEFORE
(
tdata
->
tg_event
))
pltwhen
=
PyString_FromString
(
"BEFORE"
);
pltwhen
=
PyString_FromString
(
"BEFORE"
);
else
if
(
TRIGGER_FIRED_AFTER
(
tdata
->
tg_event
))
else
if
(
TRIGGER_FIRED_AFTER
(
tdata
->
tg_event
))
...
...
src/pl/plpython/sql/plpython_function.sql
View file @
0a269db9
...
@@ -140,6 +140,37 @@ CREATE TRIGGER users_delete_trig BEFORE DELETE ON users FOR EACH ROW
...
@@ -140,6 +140,37 @@ CREATE TRIGGER users_delete_trig BEFORE DELETE ON users FOR EACH ROW
EXECUTE
PROCEDURE
users_delete
(
'willem'
);
EXECUTE
PROCEDURE
users_delete
(
'willem'
);
-- dump trigger data
CREATE
TABLE
trigger_test
(
i
int
,
v
text
);
CREATE
FUNCTION
trigger_data
()
returns
trigger
language
plpythonu
as
$$
if
TD
.
has_key
(
'relid'
):
TD
[
'relid'
]
=
"bogus:12345"
for
key
in
sorted
(
TD
.
keys
()):
val
=
TD
[
key
]
plpy
.
notice
(
"TD["
+
key
+
"] => "
+
str
(
val
))
return
None
$$
;
CREATE
TRIGGER
show_trigger_data_trig
BEFORE
INSERT
OR
UPDATE
OR
DELETE
ON
trigger_test
FOR
EACH
ROW
EXECUTE
PROCEDURE
trigger_data
(
23
,
'skidoo'
);
insert
into
trigger_test
values
(
1
,
'insert'
);
update
trigger_test
set
v
=
'update'
where
i
=
1
;
delete
from
trigger_test
;
DROP
TRIGGER
show_trigger_data_trig
on
trigger_test
;
DROP
FUNCTION
trigger_data
();
-- nested calls
-- nested calls
--
--
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment