Skip to content

Commit 020140d

Browse files
committed
PL/Python: Rename new keyword arguments of plpy.error() etc.
Rename schema -> schema_name etc. to remain consistent with C API and PL/pgSQL.
1 parent 4bc0f16 commit 020140d

File tree

4 files changed

+102
-102
lines changed

4 files changed

+102
-102
lines changed

doc/src/sgml/plpython.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,9 +1374,9 @@ $$ LANGUAGE plpythonu;
13741374
The following keyword-only arguments are accepted:
13751375
<literal>
13761376
<replaceable>detail</replaceable>, <replaceable>hint</replaceable>,
1377-
<replaceable>sqlstate</replaceable>, <replaceable>schema</replaceable>,
1378-
<replaceable>table</replaceable>, <replaceable>column</replaceable>,
1379-
<replaceable>datatype</replaceable> , <replaceable>constraint</replaceable>
1377+
<replaceable>sqlstate</replaceable>, <replaceable>schema_name</replaceable>,
1378+
<replaceable>table_name</replaceable>, <replaceable>column_name</replaceable>,
1379+
<replaceable>datatype_name</replaceable> , <replaceable>constraint_name</replaceable>
13801380
</literal>.
13811381
The string representation of the objects passed as keyword-only arguments
13821382
is used to enrich the messages reported to the client. For example:

src/pl/plpython/expected/plpython_ereport.out

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ plpy.info('This is message text.',
99
detail = 'This is detail text',
1010
hint = 'This is hint text.',
1111
sqlstate = 'XX000',
12-
schema = 'any info about schema',
13-
table = 'any info about table',
14-
column = 'any info about column',
15-
datatype = 'any info about datatype',
16-
constraint = 'any info about constraint')
12+
schema_name = 'any info about schema',
13+
table_name = 'any info about table',
14+
column_name = 'any info about column',
15+
datatype_name = 'any info about datatype',
16+
constraint_name = 'any info about constraint')
1717
plpy.notice('notice', detail = 'some detail')
1818
plpy.warning('warning', detail = 'some detail')
1919
plpy.error('stop on error', detail = 'some detail', hint = 'some hint')
@@ -70,12 +70,12 @@ CONTEXT: PL/Python anonymous code block
7070
-- raise exception in python, handle exception in plgsql
7171
CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT NULL, _hint text DEFAULT NULL,
7272
_sqlstate text DEFAULT NULL,
73-
_schema text DEFAULT NULL, _table text DEFAULT NULL, _column text DEFAULT NULL,
74-
_datatype text DEFAULT NULL, _constraint text DEFAULT NULL)
73+
_schema_name text DEFAULT NULL, _table_name text DEFAULT NULL, _column_name text DEFAULT NULL,
74+
_datatype_name text DEFAULT NULL, _constraint_name text DEFAULT NULL)
7575
RETURNS void AS $$
7676
kwargs = { "message":_message, "detail":_detail, "hint":_hint,
77-
"sqlstate":_sqlstate, "schema":_schema, "table":_table,
78-
"column":_column, "datatype":_datatype, "constraint":_constraint }
77+
"sqlstate":_sqlstate, "schema_name":_schema_name, "table_name":_table_name,
78+
"column_name":_column_name, "datatype_name":_datatype_name, "constraint_name":_constraint_name }
7979
# ignore None values - should work on Python2.3
8080
dict = {}
8181
for k in kwargs:
@@ -101,11 +101,11 @@ SELECT raise_exception(_message => 'message text',
101101
_detail => 'detail text',
102102
_hint => 'hint text',
103103
_sqlstate => 'XX555',
104-
_schema => 'schema text',
105-
_table => 'table text',
106-
_column => 'column text',
107-
_datatype => 'datatype text',
108-
_constraint => 'constraint text');
104+
_schema_name => 'schema text',
105+
_table_name => 'table text',
106+
_column_name => 'column text',
107+
_datatype_name => 'datatype text',
108+
_constraint_name => 'constraint text');
109109
ERROR: plpy.Error: message text
110110
DETAIL: detail text
111111
HINT: hint text
@@ -115,9 +115,9 @@ CONTEXT: Traceback (most recent call last):
115115
PL/Python function "raise_exception"
116116
SELECT raise_exception(_message => 'message text',
117117
_hint => 'hint text',
118-
_schema => 'schema text',
119-
_column => 'column text',
120-
_constraint => 'constraint text');
118+
_schema_name => 'schema text',
119+
_column_name => 'column text',
120+
_constraint_name => 'constraint text');
121121
ERROR: plpy.Error: message text
122122
HINT: hint text
123123
CONTEXT: Traceback (most recent call last):
@@ -133,19 +133,19 @@ DECLARE
133133
__schema_name text;
134134
__table_name text;
135135
__column_name text;
136-
__datatype text;
137-
__constraint text;
136+
__datatype_name text;
137+
__constraint_name text;
138138
BEGIN
139139
BEGIN
140140
PERFORM raise_exception(_message => 'message text',
141141
_detail => 'detail text',
142142
_hint => 'hint text',
143143
_sqlstate => 'XX555',
144-
_schema => 'schema text',
145-
_table => 'table text',
146-
_column => 'column text',
147-
_datatype => 'datatype text',
148-
_constraint => 'constraint text');
144+
_schema_name => 'schema text',
145+
_table_name => 'table text',
146+
_column_name => 'column text',
147+
_datatype_name => 'datatype text',
148+
_constraint_name => 'constraint text');
149149
EXCEPTION WHEN SQLSTATE 'XX555' THEN
150150
GET STACKED DIAGNOSTICS __message = MESSAGE_TEXT,
151151
__detail = PG_EXCEPTION_DETAIL,
@@ -154,24 +154,24 @@ BEGIN
154154
__schema_name = SCHEMA_NAME,
155155
__table_name = TABLE_NAME,
156156
__column_name = COLUMN_NAME,
157-
__datatype = PG_DATATYPE_NAME,
158-
__constraint = CONSTRAINT_NAME;
157+
__datatype_name = PG_DATATYPE_NAME,
158+
__constraint_name = CONSTRAINT_NAME;
159159
RAISE NOTICE 'handled exception'
160160
USING DETAIL = format('message:(%s), detail:(%s), hint: (%s), sqlstate: (%s), '
161-
'schema:(%s), table:(%s), column:(%s), datatype:(%s), constraint:(%s)',
161+
'schema_name:(%s), table_name:(%s), column_name:(%s), datatype_name:(%s), constraint_name:(%s)',
162162
__message, __detail, __hint, __sqlstate, __schema_name,
163-
__table_name, __column_name, __datatype, __constraint);
163+
__table_name, __column_name, __datatype_name, __constraint_name);
164164
END;
165165
END;
166166
$$;
167167
NOTICE: handled exception
168-
DETAIL: message:(plpy.Error: message text), detail:(detail text), hint: (hint text), sqlstate: (XX555), schema:(schema text), table:(table text), column:(column text), datatype:(datatype text), constraint:(constraint text)
168+
DETAIL: message:(plpy.Error: message text), detail:(detail text), hint: (hint text), sqlstate: (XX555), schema_name:(schema text), table_name:(table text), column_name:(column text), datatype_name:(datatype text), constraint_name:(constraint text)
169169
-- the displayed context is different between Python2 and Python3,
170170
-- but that's not important for this test
171171
\set SHOW_CONTEXT never
172172
do $$
173173
try:
174-
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table=> 'users_tab', _datatype => 'user_type')")
174+
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
175175
except Exception, e:
176176
plpy.info(e.spidata)
177177
raise e
@@ -181,11 +181,11 @@ ERROR: plpy.SPIError: plpy.Error: my message
181181
HINT: some hint
182182
do $$
183183
try:
184-
plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table = 'users_tab', datatype = 'user_type')
184+
plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type')
185185
except Exception, e:
186-
plpy.info('sqlstate: %s, hint: %s, tablename: %s, datatype: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
186+
plpy.info('sqlstate: %s, hint: %s, table_name: %s, datatype_name: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
187187
raise e
188188
$$ LANGUAGE plpythonu;
189-
INFO: sqlstate: XX987, hint: some hint, tablename: users_tab, datatype: user_type
189+
INFO: sqlstate: XX987, hint: some hint, table_name: users_tab, datatype_name: user_type
190190
ERROR: plpy.Error: my message
191191
HINT: some hint

src/pl/plpython/plpy_plpymodule.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
399399
char *volatile message = NULL;
400400
char *volatile detail = NULL;
401401
char *volatile hint = NULL;
402-
char *volatile column = NULL;
403-
char *volatile constraint = NULL;
404-
char *volatile datatype = NULL;
405-
char *volatile table = NULL;
406-
char *volatile schema = NULL;
402+
char *volatile column_name = NULL;
403+
char *volatile constraint_name = NULL;
404+
char *volatile datatype_name = NULL;
405+
char *volatile table_name = NULL;
406+
char *volatile schema_name = NULL;
407407
volatile MemoryContext oldcontext;
408408
PyObject *key,
409409
*value;
@@ -456,16 +456,16 @@ PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
456456
hint = object_to_string(value);
457457
else if (strcmp(keyword, "sqlstate") == 0)
458458
sqlstatestr = object_to_string(value);
459-
else if (strcmp(keyword, "schema") == 0)
460-
schema = object_to_string(value);
461-
else if (strcmp(keyword, "table") == 0)
462-
table = object_to_string(value);
463-
else if (strcmp(keyword, "column") == 0)
464-
column = object_to_string(value);
465-
else if (strcmp(keyword, "datatype") == 0)
466-
datatype = object_to_string(value);
467-
else if (strcmp(keyword, "constraint") == 0)
468-
constraint = object_to_string(value);
459+
else if (strcmp(keyword, "schema_name") == 0)
460+
schema_name = object_to_string(value);
461+
else if (strcmp(keyword, "table_name") == 0)
462+
table_name = object_to_string(value);
463+
else if (strcmp(keyword, "column_name") == 0)
464+
column_name = object_to_string(value);
465+
else if (strcmp(keyword, "datatype_name") == 0)
466+
datatype_name = object_to_string(value);
467+
else if (strcmp(keyword, "constraint_name") == 0)
468+
constraint_name = object_to_string(value);
469469
else
470470
PLy_elog(ERROR, "'%s' is an invalid keyword argument for this function",
471471
keyword);
@@ -496,32 +496,32 @@ PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
496496
pg_verifymbstr(detail, strlen(detail), false);
497497
if (hint != NULL)
498498
pg_verifymbstr(hint, strlen(hint), false);
499-
if (schema != NULL)
500-
pg_verifymbstr(schema, strlen(schema), false);
501-
if (table != NULL)
502-
pg_verifymbstr(table, strlen(table), false);
503-
if (column != NULL)
504-
pg_verifymbstr(column, strlen(column), false);
505-
if (datatype != NULL)
506-
pg_verifymbstr(datatype, strlen(datatype), false);
507-
if (constraint != NULL)
508-
pg_verifymbstr(constraint, strlen(constraint), false);
499+
if (schema_name != NULL)
500+
pg_verifymbstr(schema_name, strlen(schema_name), false);
501+
if (table_name != NULL)
502+
pg_verifymbstr(table_name, strlen(table_name), false);
503+
if (column_name != NULL)
504+
pg_verifymbstr(column_name, strlen(column_name), false);
505+
if (datatype_name != NULL)
506+
pg_verifymbstr(datatype_name, strlen(datatype_name), false);
507+
if (constraint_name != NULL)
508+
pg_verifymbstr(constraint_name, strlen(constraint_name), false);
509509

510510
ereport(level,
511511
((sqlstate != 0) ? errcode(sqlstate) : 0,
512512
(message != NULL) ? errmsg_internal("%s", message) : 0,
513513
(detail != NULL) ? errdetail_internal("%s", detail) : 0,
514514
(hint != NULL) ? errhint("%s", hint) : 0,
515-
(column != NULL) ?
516-
err_generic_string(PG_DIAG_COLUMN_NAME, column) : 0,
517-
(constraint != NULL) ?
518-
err_generic_string(PG_DIAG_CONSTRAINT_NAME, constraint) : 0,
519-
(datatype != NULL) ?
520-
err_generic_string(PG_DIAG_DATATYPE_NAME, datatype) : 0,
521-
(table != NULL) ?
522-
err_generic_string(PG_DIAG_TABLE_NAME, table) : 0,
523-
(schema != NULL) ?
524-
err_generic_string(PG_DIAG_SCHEMA_NAME, schema) : 0));
515+
(column_name != NULL) ?
516+
err_generic_string(PG_DIAG_COLUMN_NAME, column_name) : 0,
517+
(constraint_name != NULL) ?
518+
err_generic_string(PG_DIAG_CONSTRAINT_NAME, constraint_name) : 0,
519+
(datatype_name != NULL) ?
520+
err_generic_string(PG_DIAG_DATATYPE_NAME, datatype_name) : 0,
521+
(table_name != NULL) ?
522+
err_generic_string(PG_DIAG_TABLE_NAME, table_name) : 0,
523+
(schema_name != NULL) ?
524+
err_generic_string(PG_DIAG_SCHEMA_NAME, schema_name) : 0));
525525
}
526526
PG_CATCH();
527527
{

src/pl/plpython/sql/plpython_ereport.sql

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ plpy.info('This is message text.',
99
detail = 'This is detail text',
1010
hint = 'This is hint text.',
1111
sqlstate = 'XX000',
12-
schema = 'any info about schema',
13-
table = 'any info about table',
14-
column = 'any info about column',
15-
datatype = 'any info about datatype',
16-
constraint = 'any info about constraint')
12+
schema_name = 'any info about schema',
13+
table_name = 'any info about table',
14+
column_name = 'any info about column',
15+
datatype_name = 'any info about datatype',
16+
constraint_name = 'any info about constraint')
1717
plpy.notice('notice', detail = 'some detail')
1818
plpy.warning('warning', detail = 'some detail')
1919
plpy.error('stop on error', detail = 'some detail', hint = 'some hint')
@@ -43,12 +43,12 @@ do $$ plpy.info('first message', 'second message', message='third message') $$ L
4343
-- raise exception in python, handle exception in plgsql
4444
CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT NULL, _hint text DEFAULT NULL,
4545
_sqlstate text DEFAULT NULL,
46-
_schema text DEFAULT NULL, _table text DEFAULT NULL, _column text DEFAULT NULL,
47-
_datatype text DEFAULT NULL, _constraint text DEFAULT NULL)
46+
_schema_name text DEFAULT NULL, _table_name text DEFAULT NULL, _column_name text DEFAULT NULL,
47+
_datatype_name text DEFAULT NULL, _constraint_name text DEFAULT NULL)
4848
RETURNS void AS $$
4949
kwargs = { "message":_message, "detail":_detail, "hint":_hint,
50-
"sqlstate":_sqlstate, "schema":_schema, "table":_table,
51-
"column":_column, "datatype":_datatype, "constraint":_constraint }
50+
"sqlstate":_sqlstate, "schema_name":_schema_name, "table_name":_table_name,
51+
"column_name":_column_name, "datatype_name":_datatype_name, "constraint_name":_constraint_name }
5252
# ignore None values - should work on Python2.3
5353
dict = {}
5454
for k in kwargs:
@@ -63,17 +63,17 @@ SELECT raise_exception(_message => 'message text',
6363
_detail => 'detail text',
6464
_hint => 'hint text',
6565
_sqlstate => 'XX555',
66-
_schema => 'schema text',
67-
_table => 'table text',
68-
_column => 'column text',
69-
_datatype => 'datatype text',
70-
_constraint => 'constraint text');
66+
_schema_name => 'schema text',
67+
_table_name => 'table text',
68+
_column_name => 'column text',
69+
_datatype_name => 'datatype text',
70+
_constraint_name => 'constraint text');
7171

7272
SELECT raise_exception(_message => 'message text',
7373
_hint => 'hint text',
74-
_schema => 'schema text',
75-
_column => 'column text',
76-
_constraint => 'constraint text');
74+
_schema_name => 'schema text',
75+
_column_name => 'column text',
76+
_constraint_name => 'constraint text');
7777

7878
DO $$
7979
DECLARE
@@ -84,19 +84,19 @@ DECLARE
8484
__schema_name text;
8585
__table_name text;
8686
__column_name text;
87-
__datatype text;
88-
__constraint text;
87+
__datatype_name text;
88+
__constraint_name text;
8989
BEGIN
9090
BEGIN
9191
PERFORM raise_exception(_message => 'message text',
9292
_detail => 'detail text',
9393
_hint => 'hint text',
9494
_sqlstate => 'XX555',
95-
_schema => 'schema text',
96-
_table => 'table text',
97-
_column => 'column text',
98-
_datatype => 'datatype text',
99-
_constraint => 'constraint text');
95+
_schema_name => 'schema text',
96+
_table_name => 'table text',
97+
_column_name => 'column text',
98+
_datatype_name => 'datatype text',
99+
_constraint_name => 'constraint text');
100100
EXCEPTION WHEN SQLSTATE 'XX555' THEN
101101
GET STACKED DIAGNOSTICS __message = MESSAGE_TEXT,
102102
__detail = PG_EXCEPTION_DETAIL,
@@ -105,13 +105,13 @@ BEGIN
105105
__schema_name = SCHEMA_NAME,
106106
__table_name = TABLE_NAME,
107107
__column_name = COLUMN_NAME,
108-
__datatype = PG_DATATYPE_NAME,
109-
__constraint = CONSTRAINT_NAME;
108+
__datatype_name = PG_DATATYPE_NAME,
109+
__constraint_name = CONSTRAINT_NAME;
110110
RAISE NOTICE 'handled exception'
111111
USING DETAIL = format('message:(%s), detail:(%s), hint: (%s), sqlstate: (%s), '
112-
'schema:(%s), table:(%s), column:(%s), datatype:(%s), constraint:(%s)',
112+
'schema_name:(%s), table_name:(%s), column_name:(%s), datatype_name:(%s), constraint_name:(%s)',
113113
__message, __detail, __hint, __sqlstate, __schema_name,
114-
__table_name, __column_name, __datatype, __constraint);
114+
__table_name, __column_name, __datatype_name, __constraint_name);
115115
END;
116116
END;
117117
$$;
@@ -122,16 +122,16 @@ $$;
122122

123123
do $$
124124
try:
125-
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table=> 'users_tab', _datatype => 'user_type')")
125+
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
126126
except Exception, e:
127127
plpy.info(e.spidata)
128128
raise e
129129
$$ LANGUAGE plpythonu;
130130

131131
do $$
132132
try:
133-
plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table = 'users_tab', datatype = 'user_type')
133+
plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type')
134134
except Exception, e:
135-
plpy.info('sqlstate: %s, hint: %s, tablename: %s, datatype: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
135+
plpy.info('sqlstate: %s, hint: %s, table_name: %s, datatype_name: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
136136
raise e
137137
$$ LANGUAGE plpythonu;

0 commit comments

Comments
 (0)