pgsql: Add foreign data wrapper error code values for SQL/MED.

Started by Robert Haasabout 15 years ago33 messages
#1Robert Haas
rhaas@postgresql.org

Add foreign data wrapper error code values for SQL/MED.

Extracted from a much larger patch by Shigeru Hanada.

Branch
------
master

Details
-------
http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=85cff3ce7f360d139d87aee836d75a6202fee066

Modified Files
--------------
src/include/utils/errcodes.h | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#1)
Re: pgsql: Add foreign data wrapper error code values for SQL/MED.

Robert Haas <rhaas@postgresql.org> writes:

Add foreign data wrapper error code values for SQL/MED.
Extracted from a much larger patch by Shigeru Hanada.

This patch is quite incomplete. Any patch that adds to errcodes.h
*must* also touch
doc/src/sgml/errcodes.sgml
src/pl/plpgsql/src/plerrcodes.h

regards, tom lane

#3Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#2)
Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.

On Sat, Dec 25, 2010 at 3:39 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <rhaas@postgresql.org> writes:

Add foreign data wrapper error code values for SQL/MED.
Extracted from a much larger patch by Shigeru Hanada.

This patch is quite incomplete.  Any patch that adds to errcodes.h
*must* also touch
doc/src/sgml/errcodes.sgml
src/pl/plpgsql/src/plerrcodes.h

Drat. OK, will work on it tomorrow. I didn't realize those places
needed to be updated.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#4Jan Urbański
wulczer@wulczer.org
In reply to: Robert Haas (#3)
Re: Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.

On 26/12/10 05:55, Robert Haas wrote:

On Sat, Dec 25, 2010 at 3:39 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <rhaas@postgresql.org> writes:

Add foreign data wrapper error code values for SQL/MED.
Extracted from a much larger patch by Shigeru Hanada.

This patch is quite incomplete. Any patch that adds to errcodes.h
*must* also touch
doc/src/sgml/errcodes.sgml
src/pl/plpgsql/src/plerrcodes.h

Drat. OK, will work on it tomorrow. I didn't realize those places
needed to be updated.

I noticed the other day that plerrcodes.h has a comment saying is should
be generated with some sed hackery, and as I needed to generate a Python
exception class for each error in errcodes.h I did the hackery.

See
https://github.com/wulczer/postgres/commit/44fc42b7708f23483156e4e0e1e321e68b2a7e2d#diff-0
for something that maybe could be used as a basis to autogenerate
errcodes.sgml and plerrcodes.h.

Cheers,
Jan

#5Robert Haas
robertmhaas@gmail.com
In reply to: Jan Urbański (#4)
1 attachment(s)
Re: Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.

On Sun, Dec 26, 2010 at 8:03 AM, Jan Urbański <wulczer@wulczer.org> wrote:

See
https://github.com/wulczer/postgres/commit/44fc42b7708f23483156e4e0e1e321e68b2a7e2d#diff-0
for something that maybe could be used as a basis to autogenerate
errcodes.sgml and plerrcodes.h.

Interesting. It looks like this might be even easier with perl. For
now I've just written a couple of throwaway scripts to do what I
needed.

Proposed patch attached. This adds what I believe to be the correct
incantations to errcodes.sgml and plerrcodes.h, and also corrects a
typographical error in yesterday's commit which I failed to notice
while reviewing.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachments:

hv-errcodes-fix.patchtext/x-patch; charset=US-ASCII; name=hv-errcodes-fix.patchDownload
diff --git a/doc/src/sgml/errcodes.sgml b/doc/src/sgml/errcodes.sgml
index 3288687..3a1baf5 100644
--- a/doc/src/sgml/errcodes.sgml
+++ b/doc/src/sgml/errcodes.sgml
@@ -1411,6 +1411,173 @@
 
 
 <row>
+<entry spanname="span13"><emphasis role="bold">Class HV &mdash; Foreign Data Wrapper Error (SQL/MED)</></entry>
+</row>
+
+<row>
+<entry><literal>HV000</literal></entry>
+<entry>FDW ERROR</entry>
+<entry>fdw_error</entry>
+</row>
+
+<row>
+<entry><literal>HV005</literal></entry>
+<entry>FDW COLUMN NAME NOT FOUND</entry>
+<entry>fdw_column_name_not_found</entry>
+</row>
+
+<row>
+<entry><literal>HV002</literal></entry>
+<entry>FDW DYNAMIC PARAMETER VALUE NEEDED</entry>
+<entry>fdw_dynamic_parameter_value_needed</entry>
+</row>
+
+<row>
+<entry><literal>HV010</literal></entry>
+<entry>FDW FUNCTION SEQUENCE ERROR</entry>
+<entry>fdw_function_sequence_error</entry>
+</row>
+
+<row>
+<entry><literal>HV021</literal></entry>
+<entry>FDW INCONSISTENT DESCRIPTOR INFORMATION</entry>
+<entry>fdw_inconsistent_descriptor_information</entry>
+</row>
+
+<row>
+<entry><literal>HV024</literal></entry>
+<entry>FDW INVALID ATTRIBUTE VALUE</entry>
+<entry>fdw_invalid_attribute_value</entry>
+</row>
+
+<row>
+<entry><literal>HV007</literal></entry>
+<entry>FDW INVALID COLUMN NAME</entry>
+<entry>fdw_invalid_column_name</entry>
+</row>
+
+<row>
+<entry><literal>HV008</literal></entry>
+<entry>FDW INVALID COLUMN NUMBER</entry>
+<entry>fdw_invalid_column_number</entry>
+</row>
+
+<row>
+<entry><literal>HV004</literal></entry>
+<entry>FDW INVALID DATA TYPE</entry>
+<entry>fdw_invalid_data_type</entry>
+</row>
+
+<row>
+<entry><literal>HV006</literal></entry>
+<entry>FDW INVALID DATA TYPE DESCRIPTORS</entry>
+<entry>fdw_invalid_data_type_descriptors</entry>
+</row>
+
+<row>
+<entry><literal>HV091</literal></entry>
+<entry>FDW INVALID DESCRIPTOR FIELD IDENTIFIER</entry>
+<entry>fdw_invalid_descriptor_field_identifier</entry>
+</row>
+
+<row>
+<entry><literal>HV00B</literal></entry>
+<entry>FDW INVALID HANDLE</entry>
+<entry>fdw_invalid_handle</entry>
+</row>
+
+<row>
+<entry><literal>HV00C</literal></entry>
+<entry>FDW INVALID OPTION INDEX</entry>
+<entry>fdw_invalid_option_index</entry>
+</row>
+
+<row>
+<entry><literal>HV00D</literal></entry>
+<entry>FDW INVALID OPTION NAME</entry>
+<entry>fdw_invalid_option_name</entry>
+</row>
+
+<row>
+<entry><literal>HV090</literal></entry>
+<entry>FDW INVALID STRING LENGTH OR BUFFER LENGTH</entry>
+<entry>fdw_invalid_string_length_or_buffer_length</entry>
+</row>
+
+<row>
+<entry><literal>HV00A</literal></entry>
+<entry>FDW INVALID STRING FORMAT</entry>
+<entry>fdw_invalid_string_format</entry>
+</row>
+
+<row>
+<entry><literal>HV009</literal></entry>
+<entry>FDW INVALID USE OF NULL POINTER</entry>
+<entry>fdw_invalid_use_of_null_pointer</entry>
+</row>
+
+<row>
+<entry><literal>HV014</literal></entry>
+<entry>FDW TOO MANY HANDLES</entry>
+<entry>fdw_too_many_handles</entry>
+</row>
+
+<row>
+<entry><literal>HV001</literal></entry>
+<entry>FDW OUT OF MEMORY</entry>
+<entry>fdw_out_of_memory</entry>
+</row>
+
+<row>
+<entry><literal>HV00P</literal></entry>
+<entry>FDW NO SCHEMAS</entry>
+<entry>fdw_no_schemas</entry>
+</row>
+
+<row>
+<entry><literal>HV00J</literal></entry>
+<entry>FDW OPTION NAME NOT FOUND</entry>
+<entry>fdw_option_name_not_found</entry>
+</row>
+
+<row>
+<entry><literal>HV00K</literal></entry>
+<entry>FDW REPLY HANDLE</entry>
+<entry>fdw_reply_handle</entry>
+</row>
+
+<row>
+<entry><literal>HV00Q</literal></entry>
+<entry>FDW SCHEMA NOT FOUND</entry>
+<entry>fdw_schema_not_found</entry>
+</row>
+
+<row>
+<entry><literal>HV00R</literal></entry>
+<entry>FDW TABLE NOT FOUND</entry>
+<entry>fdw_table_not_found</entry>
+</row>
+
+<row>
+<entry><literal>HV00L</literal></entry>
+<entry>FDW UNABLE TO CREATE EXECUTION</entry>
+<entry>fdw_unable_to_create_execution</entry>
+</row>
+
+<row>
+<entry><literal>HV00M</literal></entry>
+<entry>FDW UNABLE TO CREATE REPLY</entry>
+<entry>fdw_unable_to_create_reply</entry>
+</row>
+
+<row>
+<entry><literal>HV00N</literal></entry>
+<entry>FDW UNABLE TO ESTABLISH CONNECTION</entry>
+<entry>fdw_unable_to_establish_connection</entry>
+</row>
+
+
+<row>
 <entry spanname="span13"><emphasis role="bold">Class P0 &mdash; PL/pgSQL Error</></entry>
 </row>
 
diff --git a/src/include/utils/errcodes.h b/src/include/utils/errcodes.h
index 3b332b6..80a4ca1 100644
--- a/src/include/utils/errcodes.h
+++ b/src/include/utils/errcodes.h
@@ -368,7 +368,7 @@
 #define ERRCODE_FDW_REPLY_HANDLE			MAKE_SQLSTATE('H','V', '0','0','K')
 #define ERRCODE_FDW_SCHEMA_NOT_FOUND		MAKE_SQLSTATE('H','V', '0','0','Q')
 #define ERRCODE_FDW_TABLE_NOT_FOUND			MAKE_SQLSTATE('H','V', '0','0','R')
-#define ERRCODE_FDW_UNALBE_TO_CREATE_EXECUTION	MAKE_SQLSTATE('H','V', '0','0','L')
+#define ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION	MAKE_SQLSTATE('H','V', '0','0','L')
 #define ERRCODE_FDW_UNABLE_TO_CREATE_REPLY	MAKE_SQLSTATE('H','V', '0','0','M')
 #define ERRCODE_FDW_UNABLE_TO_ESTABLISH_CONNECTION	MAKE_SQLSTATE('H','V', '0','0','N')
 
diff --git a/src/pl/plpgsql/src/plerrcodes.h b/src/pl/plpgsql/src/plerrcodes.h
index 30465de..1bcc4d6 100644
--- a/src/pl/plpgsql/src/plerrcodes.h
+++ b/src/pl/plpgsql/src/plerrcodes.h
@@ -760,6 +760,114 @@
 },
 
 {
+	"fdw_error", ERRCODE_FDW_ERROR
+},
+
+{
+	"fdw_column_name_not_found", ERRCODE_FDW_COLUMN_NAME_NOT_FOUND
+},
+
+{
+	"fdw_dynamic_parameter_value_needed", ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED
+},
+
+{
+	"fdw_function_sequence_error", ERRCODE_FDW_FUNCTION_SEQUENCE_ERROR
+},
+
+{
+	"fdw_inconsistent_descriptor_information", ERRCODE_FDW_INCONSISTENT_DESCRIPTOR_INFORMATION
+},
+
+{
+	"fdw_invalid_attribute_value", ERRCODE_FDW_INVALID_ATTRIBUTE_VALUE
+},
+
+{
+	"fdw_invalid_column_name", ERRCODE_FDW_INVALID_COLUMN_NAME
+},
+
+{
+	"fdw_invalid_column_number", ERRCODE_FDW_INVALID_COLUMN_NUMBER
+},
+
+{
+	"fdw_invalid_data_type", ERRCODE_FDW_INVALID_DATA_TYPE
+},
+
+{
+	"fdw_invalid_data_type_descriptors", ERRCODE_FDW_INVALID_DATA_TYPE_DESCRIPTORS
+},
+
+{
+	"fdw_invalid_descriptor_field_identifier", ERRCODE_FDW_INVALID_DESCRIPTOR_FIELD_IDENTIFIER
+},
+
+{
+	"fdw_invalid_handle", ERRCODE_FDW_INVALID_HANDLE
+},
+
+{
+	"fdw_invalid_option_index", ERRCODE_FDW_INVALID_OPTION_INDEX
+},
+
+{
+	"fdw_invalid_option_name", ERRCODE_FDW_INVALID_OPTION_NAME
+},
+
+{
+	"fdw_invalid_string_length_or_buffer_length", ERRCODE_FDW_INVALID_STRING_LENGTH_OR_BUFFER_LENGTH
+},
+
+{
+	"fdw_invalid_string_format", ERRCODE_FDW_INVALID_STRING_FORMAT
+},
+
+{
+	"fdw_invalid_use_of_null_pointer", ERRCODE_FDW_INVALID_USE_OF_NULL_POINTER
+},
+
+{
+	"fdw_too_many_handles", ERRCODE_FDW_TOO_MANY_HANDLES
+},
+
+{
+	"fdw_out_of_memory", ERRCODE_FDW_OUT_OF_MEMORY
+},
+
+{
+	"fdw_no_schemas", ERRCODE_FDW_NO_SCHEMAS
+},
+
+{
+	"fdw_option_name_not_found", ERRCODE_FDW_OPTION_NAME_NOT_FOUND
+},
+
+{
+	"fdw_reply_handle", ERRCODE_FDW_REPLY_HANDLE
+},
+
+{
+	"fdw_schema_not_found", ERRCODE_FDW_SCHEMA_NOT_FOUND
+},
+
+{
+	"fdw_table_not_found", ERRCODE_FDW_TABLE_NOT_FOUND
+},
+
+{
+	"fdw_unable_to_create_execution", ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION
+},
+
+{
+	"fdw_unable_to_create_reply", ERRCODE_FDW_UNABLE_TO_CREATE_REPLY
+},
+
+{
+	"fdw_unable_to_establish_connection", ERRCODE_FDW_UNABLE_TO_ESTABLISH_CONNECTION
+},
+
+{
 	"raise_exception", ERRCODE_RAISE_EXCEPTION
 },
 
#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#5)
Re: Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.

Robert Haas <robertmhaas@gmail.com> writes:

On Sun, Dec 26, 2010 at 8:03 AM, Jan Urbański <wulczer@wulczer.org> wrote:

See
https://github.com/wulczer/postgres/commit/44fc42b7708f23483156e4e0e1e321e68b2a7e2d#diff-0
for something that maybe could be used as a basis to autogenerate
errcodes.sgml and plerrcodes.h.

Interesting. It looks like this might be even easier with perl.

The reason those files aren't autogenerated already is that at the time,
we had a policy of not requiring perl during a build. Now that that
restriction has gone down the drain, it might be worth thinking about.

Proposed patch attached. This adds what I believe to be the correct
incantations to errcodes.sgml and plerrcodes.h, and also corrects a
typographical error in yesterday's commit which I failed to notice
while reviewing.

Hmm. Even with the typo fixed, ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION
seems pretty darn opaque. Is it missing a word? Can we rephrase it so
people will have some idea what it means?

regards, tom lane

#7Jan Urbański
wulczer@wulczer.org
In reply to: Tom Lane (#6)
autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 26/12/10 18:17, Tom Lane wrote:

Robert Haas <robertmhaas@gmail.com> writes:

On Sun, Dec 26, 2010 at 8:03 AM, Jan Urbański <wulczer@wulczer.org> wrote:

See
https://github.com/wulczer/postgres/commit/44fc42b7708f23483156e4e0e1e321e68b2a7e2d#diff-0
for something that maybe could be used as a basis to autogenerate
errcodes.sgml and plerrcodes.h.

Interesting. It looks like this might be even easier with perl.

The reason those files aren't autogenerated already is that at the time,
we had a policy of not requiring perl during a build. Now that that
restriction has gone down the drain, it might be worth thinking about.

I took a crack at doing that for PL/Python and came up with this piece
of Perl:

https://github.com/wulczer/postgres/blob/616d08178519b61ab5446aa63277e9d7e4841d60/src/pl/plpython/generate-spiexceptions.pl

I then tried to do the same for plerrcodes.h, but found discrepancies.
For instance:

* errcodes.h defines ERRCODE_L_E_INVALID_SPECIFICATION and plerrcodes.h
has "invalid_locator_specification".

* ERRCODE_INVALID_ARGUMENT_FOR_LOG becomes "invalid_argument_for_logarithm"

* ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT is
"function_executed_no_return_statement"

* ... and quite some more like this

Additionally, there's one error missing from plerrcodes.h -
ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER does not appear there.

Should we a) forget about autogenerating plerrcodes.h and errcodes.sgml
or b) hardcode some exceptions in the Perl script? Changing condition
names would be a big backwards-compat no-no, I presume.

Cheers,
Jan

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Urbański (#7)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

I then tried to do the same for plerrcodes.h, but found discrepancies.

You shouldn't assume that errcodes.h necessarily includes all the info
needed to create the other two files.

The way I'd envision this working is that we have a master file
containing the five-letter SQLSTATE code, the ERRCODE macro name,
the string name to use in plerrcodes.h, and any other required items,
and then generate all three of the existing files from that.

regards, tom lane

#9Jan Urbański
wulczer@wulczer.org
In reply to: Tom Lane (#8)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 26/12/10 20:33, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

I then tried to do the same for plerrcodes.h, but found discrepancies.

You shouldn't assume that errcodes.h necessarily includes all the info
needed to create the other two files.

The way I'd envision this working is that we have a master file
containing the five-letter SQLSTATE code, the ERRCODE macro name,
the string name to use in plerrcodes.h, and any other required items,
and then generate all three of the existing files from that.

How about a format like this then:

# Comment
Section: Class 2F - SQL Routine Exception
macro_name sqlstate plpgsqlname is_error

That is: # and blank lines are comments, lines starting with "Section:"
are section names (needed for SGML output), the rest are whitespace
separated strings. is_error is 0 or 1, if it's 0 we don't generate a
plpgsql condition for it.

If we go for that format, we'll end up with one new plpgsql error
(nonstantard_use_of_escape_character) that was omitted from previous
releases.

Jan

#10Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Urbański (#9)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

How about a format like this then:

# Comment
Section: Class 2F - SQL Routine Exception
macro_name sqlstate plpgsqlname is_error

That is: # and blank lines are comments, lines starting with "Section:"
are section names (needed for SGML output), the rest are whitespace
separated strings. is_error is 0 or 1, if it's 0 we don't generate a
plpgsql condition for it.

Or just leave out the plpgsqlname if we don't want a condition to be
generated?

Things might line up nicer if the sqlstate is the first column.

regards, tom lane

#11Jan Urbański
wulczer@wulczer.org
In reply to: Tom Lane (#10)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 26/12/10 20:57, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

How about a format like this then:

# Comment
Section: Class 2F - SQL Routine Exception
macro_name sqlstate plpgsqlname is_error

That is: # and blank lines are comments, lines starting with "Section:"
are section names (needed for SGML output), the rest are whitespace
separated strings. is_error is 0 or 1, if it's 0 we don't generate a
plpgsql condition for it.

Or just leave out the plpgsqlname if we don't want a condition to be
generated?

Makes sense. Wait, no, errcodes.sgml includes the entries for success
and warnings, but the plpgsql conditions list does not. So we need a
separate column to differentiate.

Things might line up nicer if the sqlstate is the first column.

I was thinking of separating the values with tabs anyway, but I'm fine
with putting sqlstate first.

Cheers,
Jan

#12Robert Haas
robertmhaas@gmail.com
In reply to: Jan Urbański (#11)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On Dec 26, 2010, at 3:09 PM, Jan Urbański <wulczer@wulczer.org> wrote:

Things might line up nicer if the sqlstate is the first column.

I was thinking of separating the values with tabs anyway, but I'm fine
with putting sqlstate first.

+1 for putting SQLSTATE first.

...Robert

#13Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Urbański (#11)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

Makes sense. Wait, no, errcodes.sgml includes the entries for success
and warnings, but the plpgsql conditions list does not. So we need a
separate column to differentiate.

OK. But not 0/1 please. Maybe 'E', 'W', or 'S' ? And again, fixed
width columns first, so something like

sqlstate E/W/S errcode_macro_name plpgsql_condition_name

where I guess we could still make the plpgsql condition name optional.

regards, tom lane

#14Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#6)
Re: Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.

On Sun, Dec 26, 2010 at 12:17 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Proposed patch attached.  This adds what I believe to be the correct
incantations to errcodes.sgml and plerrcodes.h, and also corrects a
typographical error in yesterday's commit which I failed to notice
while reviewing.

Hmm.  Even with the typo fixed, ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION
seems pretty darn opaque.  Is it missing a word?  Can we rephrase it so
people will have some idea what it means?

(looks at a draft copy of the spec)

Appears to be straight out of the spec. There's also some
incomprehensible (to me) language explaining what it's supposed to
mean. I think they're using the term "FDW execution" to mean
something along the lines of "an instance of grabbing data via an
FDW". Or something sort of vaguely like that. If I didn't know
better I'd think this had been deliberately obfuscated.

At any rate, I think rewording language straight out of the spec is
likely a bad plan.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#15Jan Urbański
wulczer@wulczer.org
In reply to: Tom Lane (#13)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 26/12/10 21:17, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

Makes sense. Wait, no, errcodes.sgml includes the entries for success
and warnings, but the plpgsql conditions list does not. So we need a
separate column to differentiate.

OK. But not 0/1 please. Maybe 'E', 'W', or 'S' ? And again, fixed
width columns first, so something like

sqlstate E/W/S errcode_macro_name plpgsql_condition_name

where I guess we could still make the plpgsql condition name optional.

All right, E/W/S sounds good. I'm actually faulty of a misnomer by
calling the field plpgsql_condition_name. It's more like spec_name, and
it will be used to generate plpgsql condition names for E entries and
rows in errcodes.sgml for all entries.

Remember that there will also be Section: lines there, because
errcodes.sgml needs to know where particular the error classes start and
end.

So:

sqlstate E/W/S errcode_macro_name spec_name

where spec_name is lowercase and underscore-separated.

errcodes.h would be generated by splitting sqlstate into letters and
emitting `#define errcode_macro_name MAKE_SQLSTATE('x','x','x','x','x')'

plerrcodes.h would be generated by emitting `{ "spec_name",
errcode_macro_name },' for each E line

errcodes.sgml would be generated by emitting a <row/> element with
sqlstate, spec_name in uppercase and with underscores stripped and just
spec_name. The Section: lines would generate table headers.

... and spiexceptions.h in plpython would be "spec_name" with
underscores converted to camel case and errcode_macro_name

How does that sound?

Jan

#16Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#14)
Re: Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.

Robert Haas <robertmhaas@gmail.com> writes:

On Sun, Dec 26, 2010 at 12:17 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Hmm. �Even with the typo fixed, ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION
seems pretty darn opaque. �Is it missing a word? �Can we rephrase it so
people will have some idea what it means?

Appears to be straight out of the spec.

Oh, okay.

At any rate, I think rewording language straight out of the spec is
likely a bad plan.

Agreed.

regards, tom lane

#17Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#16)
Re: Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.

On Sun, Dec 26, 2010 at 4:18 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <robertmhaas@gmail.com> writes:

On Sun, Dec 26, 2010 at 12:17 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Hmm.  Even with the typo fixed, ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION
seems pretty darn opaque.  Is it missing a word?  Can we rephrase it so
people will have some idea what it means?

Appears to be straight out of the spec.

Oh, okay.

At any rate, I think rewording language straight out of the spec is
likely a bad plan.

Agreed.

OK, committed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#18Jan Urbański
wulczer@wulczer.org
In reply to: Jan Urbański (#15)
4 attachment(s)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 26/12/10 21:33, Jan Urbański wrote:

On 26/12/10 21:17, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

Makes sense. Wait, no, errcodes.sgml includes the entries for success
and warnings, but the plpgsql conditions list does not. So we need a
separate column to differentiate.

OK. But not 0/1 please. Maybe 'E', 'W', or 'S' ? And again, fixed
width columns first, so something like

sqlstate E/W/S errcode_macro_name plpgsql_condition_name

where I guess we could still make the plpgsql condition name optional.

All right, E/W/S sounds good. I'm actually faulty of a misnomer by
calling the field plpgsql_condition_name. It's more like spec_name, and
it will be used to generate plpgsql condition names for E entries and
rows in errcodes.sgml for all entries.

Remember that there will also be Section: lines there, because
errcodes.sgml needs to know where particular the error classes start and
end.

Here's the basic errcodes.txt file and three scripts to generate
errcodes.h, plerrcodes.h and part of errcodes.sgml.

I tried wiring it into the build system, but failed, I can't figure out
which Makefiles should be updated in order to make errcodes.h and
plerrcodes.h generated headers. Could someone help with that?

This will actually remove a few entries from plerrcodes.h, that were
aliases of other entries (like array_element_error which was an alias of
array_subscript_error). Since they did not appear in errcodes.sgml, it
shouldn't be a problem.

It also adds a forgotten entry for nonstandard_use_of_escape_character
in plerrcodes.h.

Cheers,
Jan

Attachments:

errcodes.txttext/plain; name=errcodes.txtDownload
generate-errcodes.pltext/x-perl; name=generate-errcodes.plDownload
generate-plerrcodes.pltext/x-perl; name=generate-plerrcodes.plDownload
generate-errcodes-table.pltext/x-perl; name=generate-errcodes-table.plDownload
#19Jan Urbański
wulczer@wulczer.org
In reply to: Jan Urbański (#18)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 28/12/10 12:25, Jan Urbański wrote:

Here's the basic errcodes.txt file and three scripts to generate
errcodes.h, plerrcodes.h and part of errcodes.sgml.

I tried wiring it into the build system, but failed, I can't figure out
which Makefiles should be updated in order to make errcodes.h and
plerrcodes.h generated headers. Could someone help with that?

Trying a bit harder to make src/include/utils/errcodes.h a generated
file I found that it's included so early it makes the task not trivial
at all. postgres.h includes elog.h, which includes errcodes.h (after
defining the MAKE_SQLSTATE macro). I'm not sure how to proceed:

1) just give up on it, and keep on maintaining 3 places where new error
codes have to go
2) do not include errcodes.h in elog.h, move the MAKE_SQLSTATE
definition to the top of errcodes.h, guarded by a #ifndef MAKE_SQLSTATE,
fix every place that included elog.h and assumed it has the sqlstate
values to explicitly include errcodes.h. This means that you can still
define your own MAKE_SQLSTATE macro and then include errcodes.h if you
want to redefine what it does.
3) try to wire generating errcodes.h somewhere very early in the makefiles

My preference is 2) followed by 1), because 3) seems too horrible. But I
can understand if people will want to keep things as they are and just
forget about generating errcodes.h

Cheers,
Jan

#20Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Urbański (#19)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

I tried wiring it into the build system, but failed, I can't figure out
which Makefiles should be updated in order to make errcodes.h and
plerrcodes.h generated headers. Could someone help with that?

Trying a bit harder to make src/include/utils/errcodes.h a generated
file I found that it's included so early it makes the task not trivial
at all. postgres.h includes elog.h, which includes errcodes.h (after
defining the MAKE_SQLSTATE macro). I'm not sure how to proceed:

Huh? Why in the world would the specific location of the #include have
anything to do with the problem?

regards, tom lane

#21Jan Urbański
wulczer@wulczer.org
In reply to: Tom Lane (#20)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 11/01/11 17:11, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

I tried wiring it into the build system, but failed, I can't figure out
which Makefiles should be updated in order to make errcodes.h and
plerrcodes.h generated headers. Could someone help with that?

Trying a bit harder to make src/include/utils/errcodes.h a generated
file I found that it's included so early it makes the task not trivial
at all. postgres.h includes elog.h, which includes errcodes.h (after
defining the MAKE_SQLSTATE macro). I'm not sure how to proceed:

Huh? Why in the world would the specific location of the #include have
anything to do with the problem?

I'v having a hard time convincing make to generate errcodes.h before
compiling any .c file that includes postgres.h. The only way I found was
to make src/include/errcodes.h a dependancy of the all target.

For instance, I tried to copy the way we generate fmgroids.h and it
turned out that it doesn't work (it tries to compile things in src/port
before entering src/include, and things in src/port include postgres.h).

#22Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Urbański (#21)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

On 11/01/11 17:11, Tom Lane wrote:

Huh? Why in the world would the specific location of the #include have
anything to do with the problem?

I'v having a hard time convincing make to generate errcodes.h before
compiling any .c file that includes postgres.h. The only way I found was
to make src/include/errcodes.h a dependancy of the all target.

Peter would probably be a better person than me to answer that, but I
imagine that what you want is similar to what src/backend/Makefile does
for parser/gram.h, only applied at the src/ level or maybe even the
root.

regards, tom lane

#23Jan Urbański
wulczer@wulczer.org
In reply to: Tom Lane (#22)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 11/01/11 18:59, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

On 11/01/11 17:11, Tom Lane wrote:

Huh? Why in the world would the specific location of the #include have
anything to do with the problem?

I'v having a hard time convincing make to generate errcodes.h before
compiling any .c file that includes postgres.h. The only way I found was
to make src/include/errcodes.h a dependancy of the all target.

Peter would probably be a better person than me to answer that, but I
imagine that what you want is similar to what src/backend/Makefile does
for parser/gram.h, only applied at the src/ level or maybe even the
root.

OK, that was a nudge in the right direction. Basing the rules from
src/backend/Makefile I changed src/Makefile to rebuild
src/include/errcodes.h before building the subdirectories and... it
failed miserably. There's some trickery beyond my understanding here.
There's a rule like this in src/backend/Makefile:

$(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/gram.h

that triggers checking whether gram.h needs to be rebuilt before
recursing into each SUBDIR.

A similar trick in src/Makefile doesn't work, because it's
src/backend/common.mk that is responsible for the SUBDIR-recursive
calls, and src/Makefile does not include it.

From what I gathered by reading Makefile.global, the $(recurse) call in
enters each SUBDIR and builds a target called <target>-<subdir>-recurse.
And actually, if I change my rule to read:

$(SUBDIRS:%=all-%-recurse): $(top_builddir)/src/include/utils/errcodes.h

it works. Now whether that's acceptable or not is another thing entirely...

Cheers,
Jan

#24Jan Urbański
wulczer@wulczer.org
In reply to: Jan Urbański (#23)
1 attachment(s)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 11/01/11 21:21, Jan Urbański wrote:

On 11/01/11 18:59, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

On 11/01/11 17:11, Tom Lane wrote:

Peter would probably be a better person than me to answer that, but I
imagine that what you want is similar to what src/backend/Makefile does
for parser/gram.h, only applied at the src/ level or maybe even the
root.

And actually, if I change my rule to read:

$(SUBDIRS:%=all-%-recurse): $(top_builddir)/src/include/utils/errcodes.h

it works. Now whether that's acceptable or not is another thing entirely...

And so I came up with three patches to make errcodes.h, plerrcodes.h and
errcodes.sgml (respectively) generated files.

The autogenerated files are almost identical with the originals (except
for formatting, sometimes, and comments) except:

* in errcodes.sgml the Meaning field for INVALID ARGUMENT FOR NTH_VALUE
FUNCTION changed to INVALID ARGUMENT FOR NTH VALUE FUNCTION. Not ideal,
but I wouldn't shed any tears. The Constant field stays the same, and
that's what's important for a PL/pgSQL programmer

* in errcodes.h there are a few changes like that:

 #define ERRCODE_DATETIME_FIELD_OVERFLOW        MAKE_SQLSTATE('2','2',
'0','0','8')
-#define ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ERRCODE_DATETIME_FIELD_OVERFLOW
+#define ERRCODE_DATETIME_VALUE_OUT_OF_RANGE
MAKE_SQLSTATE('2','2','0','0','8')
 #define ERRCODE_DIVISION_BY_ZERO           MAKE_SQLSTATE('2','2',
'0','1','2')

unless your MAKE_SQLSTATE macro has side-effects, it should not be a problem

* in plerrcodes.h a few entries disappeard, and that's because they had
duplicated SQLSTATE values. As they were not documented in
errcodes.sgml, no one should even know they existed, and as they catch
the same SQLSTATE, again it shouldn't be an issue.

As a bonus, a documented but forgotten exception got added. Try this in
HEAD:

do $$ begin begin exception when nonstandard_use_of_escape_character
then null; end; end$$;

It will fail.

Cheers,
Jan

Attachments:

0003-Generate-the-error-codes-appendix-file.patchtext/x-patch; name=0003-Generate-the-error-codes-appendix-file.patchDownload
#25Jan Urbański
wulczer@wulczer.org
In reply to: Jan Urbański (#24)
1 attachment(s)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 12/01/11 19:57, Jan Urbański wrote:

On 11/01/11 21:21, Jan Urbański wrote:

On 11/01/11 18:59, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

On 11/01/11 17:11, Tom Lane wrote:

Peter would probably be a better person than me to answer that, but I
imagine that what you want is similar to what src/backend/Makefile does
for parser/gram.h, only applied at the src/ level or maybe even the
root.

And actually, if I change my rule to read:

$(SUBDIRS:%=all-%-recurse): $(top_builddir)/src/include/utils/errcodes.h

it works. Now whether that's acceptable or not is another thing entirely...

And so I came up with three patches to make errcodes.h, plerrcodes.h and
errcodes.sgml (respectively) generated files.

Darn, forgot about MSVC again. See
http://archives.postgresql.org/message-id/4D2DF996.9000100@wulczer.org
for details on how this works.

Attached are the previous 3 patches and a fourth one that adds MSVC support.

Cheers,
Jan

Attachments:

0004-Add-MSVC-support-for-generating-files-based-on-errco.patchtext/x-patch; name=0004-Add-MSVC-support-for-generating-files-based-on-errco.patchDownload
#26Robert Haas
robertmhaas@gmail.com
In reply to: Jan Urbański (#25)
1 attachment(s)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On Wed, Jan 12, 2011 at 5:10 PM, Jan Urbański <wulczer@wulczer.org> wrote:

On 12/01/11 19:57, Jan Urbański wrote:

On 11/01/11 21:21, Jan Urbański wrote:

On 11/01/11 18:59, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

On 11/01/11 17:11, Tom Lane wrote:

Peter would probably be a better person than me to answer that, but I
imagine that what you want is similar to what src/backend/Makefile does
for parser/gram.h, only applied at the src/ level or maybe even the
root.

And actually, if I change my rule to read:

$(SUBDIRS:%=all-%-recurse): $(top_builddir)/src/include/utils/errcodes.h

it works. Now whether that's acceptable or not is another thing entirely...

And so I came up with three patches to make errcodes.h, plerrcodes.h and
errcodes.sgml (respectively) generated files.

Darn, forgot about MSVC again. See
http://archives.postgresql.org/message-id/4D2DF996.9000100@wulczer.org
for details on how this works.

Attached are the previous 3 patches and a fourth one that adds MSVC support.

I think these look good. I'm not sure there's any value in stripping
the duplicates out of plerrcodes.h, though, even if they were
undocumented:

- "array_element_error", ERRCODE_ARRAY_ELEMENT_ERROR
- "datetime_value_out_of_range", ERRCODE_DATETIME_VALUE_OUT_OF_RANGE
- "undefined_cursor", ERRCODE_UNDEFINED_CURSOR
- "undefined_database", ERRCODE_UNDEFINED_DATABASE
- "undefined_pstatement", ERRCODE_UNDEFINED_PSTATEMENT
- "undefined_schema", ERRCODE_UNDEFINED_SCHEMA

I'm attaching a few other proposed adjustments.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachments:

errcodes-adjustments.patchtext/x-diff; charset=US-ASCII; name=errcodes-adjustments.patchDownload
diff --git a/doc/src/sgml/.gitignore b/doc/src/sgml/.gitignore
index 62a38d2..e1b84b4 100644
--- a/doc/src/sgml/.gitignore
+++ b/doc/src/sgml/.gitignore
@@ -16,6 +16,7 @@
 # GENERATED_SGML
 /features-supported.sgml
 /features-unsupported.sgml
+/errcodes-table.sgml
 /version.sgml
 /bookindex.sgml
 /HTML.index
diff --git a/doc/src/sgml/Makefile b/doc/src/sgml/Makefile
index 59d8692..fe70d8e 100644
--- a/doc/src/sgml/Makefile
+++ b/doc/src/sgml/Makefile
@@ -137,7 +137,7 @@ features-unsupported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_package
 	$(PERL) $(srcdir)/mk_feature_tables.pl NO $^ > $@
 
 errcodes-table.sgml: $(top_srcdir)/src/include/utils/errcodes.txt generate-errcodes-table.pl
-	$(PERL) generate-errcodes-table.pl $< > $@
+	$(PERL) $(srcdir)/generate-errcodes-table.pl $< > $@
 
 ##
 ## Print
diff --git a/src/backend/utils/.gitignore b/src/backend/utils/.gitignore
index fd00851..5c3a565 100644
--- a/src/backend/utils/.gitignore
+++ b/src/backend/utils/.gitignore
@@ -1,3 +1,4 @@
 /fmgrtab.c
 /fmgroids.h
 /probes.h
+/errcodes.h
diff --git a/src/backend/utils/generate-errcodes.pl b/src/backend/utils/generate-errcodes.pl
index 592ad66..3469f19 100644
--- a/src/backend/utils/generate-errcodes.pl
+++ b/src/backend/utils/generate-errcodes.pl
@@ -17,10 +17,15 @@ while (<$errcodes>) {
     next if /^#/;
     next if /^\s*$/;
 
-    # Skip section headers
-    next if /^Section:/;
-
-    die unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/;
+    # Omit a comment for each section header
+    if (/^Section:(.*)/) {
+		my $header = $1;
+		$header =~ s/^\s+//;
+		print "\n/* $header */\n";
+		next;
+	}
+
+    die "unable to parse errcodes.txt" unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/;
 
     (my $sqlstate, my $errcode_macro) = ($1, $2);
 
diff --git a/src/include/utils/.gitignore b/src/include/utils/.gitignore
index c7c402b..808826d 100644
--- a/src/include/utils/.gitignore
+++ b/src/include/utils/.gitignore
@@ -1,2 +1,3 @@
 /fmgroids.h
 /probes.h
+/errcodes.h
diff --git a/src/pl/plpgsql/src/.gitignore b/src/pl/plpgsql/src/.gitignore
index 2eecb0f..92387fa 100644
--- a/src/pl/plpgsql/src/.gitignore
+++ b/src/pl/plpgsql/src/.gitignore
@@ -1,2 +1,3 @@
 /pl_gram.c
 /pl_gram.h
+/plerrcodes.h
#27Jan Urbański
wulczer@wulczer.org
In reply to: Robert Haas (#26)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On 30/01/11 23:08, Robert Haas wrote:

On Wed, Jan 12, 2011 at 5:10 PM, Jan Urbański <wulczer@wulczer.org> wrote:

On 12/01/11 19:57, Jan Urbański wrote:

On 11/01/11 21:21, Jan Urbański wrote:

On 11/01/11 18:59, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

On 11/01/11 17:11, Tom Lane wrote:

Peter would probably be a better person than me to answer that, but I
imagine that what you want is similar to what src/backend/Makefile does
for parser/gram.h, only applied at the src/ level or maybe even the
root.

And actually, if I change my rule to read:

$(SUBDIRS:%=all-%-recurse): $(top_builddir)/src/include/utils/errcodes.h

it works. Now whether that's acceptable or not is another thing entirely...

And so I came up with three patches to make errcodes.h, plerrcodes.h and
errcodes.sgml (respectively) generated files.

Darn, forgot about MSVC again. See
http://archives.postgresql.org/message-id/4D2DF996.9000100@wulczer.org
for details on how this works.

Attached are the previous 3 patches and a fourth one that adds MSVC support.

I think these look good. I'm not sure there's any value in stripping
the duplicates out of plerrcodes.h, though, even if they were
undocumented:

I think that if you don't strip them out, they will get documented (as
the SGML is generated).

For PL/pgSQL nothing horrible will happen, because if you write
EXCEPTION WHEN foo, it will look up the "foo" label and then compare the
exception's SQLSTATE to decide if it should be handled by that block.
But for PL/Python, the process is reverse: the exception object is
looked up by looking at the SQLSTATE and then injected into Python, so
if SQLSTATE 12345 is both foo_error and bar_error, and you write

try:
buggy()
except FooError:
handle_it()

you might be out of luck, if BarError is first on the list, as it will
match the SQLSTATE of the error from buggy() and your except clause will
be useless. AFAICS there's no way to do it another way, short of
dropping the idea of having names for specific exceptions, and forcing
the user to do:

try:
buggy()
except SPIError as e:
if e.sqlstate == plpy.condition_to_sqlstate("foo_error"):
handle_it()
else:
raise

which is ugly. It would be useful to have a 1-1 mapping between
condition names and SQLSTATE codes.

I'm attaching a few other proposed adjustments.

Right, forgot about .gitignores.

Cheers,
Jan

#28Robert Haas
robertmhaas@gmail.com
In reply to: Jan Urbański (#27)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On Sun, Jan 30, 2011 at 5:23 PM, Jan Urbański <wulczer@wulczer.org> wrote:

On 30/01/11 23:08, Robert Haas wrote:

On Wed, Jan 12, 2011 at 5:10 PM, Jan Urbański <wulczer@wulczer.org> wrote:

On 12/01/11 19:57, Jan Urbański wrote:

On 11/01/11 21:21, Jan Urbański wrote:

On 11/01/11 18:59, Tom Lane wrote:

=?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= <wulczer@wulczer.org> writes:

On 11/01/11 17:11, Tom Lane wrote:

Peter would probably be a better person than me to answer that, but I
imagine that what you want is similar to what src/backend/Makefile does
for parser/gram.h, only applied at the src/ level or maybe even the
root.

And actually, if I change my rule to read:

$(SUBDIRS:%=all-%-recurse): $(top_builddir)/src/include/utils/errcodes.h

it works. Now whether that's acceptable or not is another thing entirely...

And so I came up with three patches to make errcodes.h, plerrcodes.h and
errcodes.sgml (respectively) generated files.

Darn, forgot about MSVC again. See
http://archives.postgresql.org/message-id/4D2DF996.9000100@wulczer.org
for details on how this works.

Attached are the previous 3 patches and a fourth one that adds MSVC support.

I think these look good.  I'm not sure there's any value in stripping
the duplicates out of plerrcodes.h, though, even if they were
undocumented:

I think that if you don't strip them out, they will get documented (as
the SGML is generated).

For PL/pgSQL nothing horrible will happen, because if you write
EXCEPTION WHEN foo, it will look up the "foo" label and then compare the
exception's SQLSTATE to decide if it should be handled by that block.
But for PL/Python, the process is reverse: the exception object is
looked up by looking at the SQLSTATE and then injected into Python

OK. If there's a reason for doing it this way, I'm OK with it.

I'll mark this one Ready for Committer.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#29Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#28)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

Robert Haas <robertmhaas@gmail.com> writes:

I'll mark this one Ready for Committer.

If you don't want to commit it yourself, I'll take it.

regards, tom lane

#30Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#29)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On Sun, Jan 30, 2011 at 5:47 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <robertmhaas@gmail.com> writes:

I'll mark this one Ready for Committer.

If you don't want to commit it yourself, I'll take it.

I'm happy to do it. I would have done it straight off, but thought
I'd give everyone one last chance to kvetch.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#31Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#30)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

Robert Haas <robertmhaas@gmail.com> writes:

On Sun, Jan 30, 2011 at 5:47 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

If you don't want to commit it yourself, I'll take it.

I'm happy to do it. I would have done it straight off, but thought
I'd give everyone one last chance to kvetch.

Just in a quick read-through of the patches, the only things I noticed
were (1) lack of a PGDG copyright notice in errcodes.txt, and (2)
in your proposed change to generate-errcodes.pl:

+    # Omit a comment for each section header
+    if (/^Section:(.*)/) {
+		my $header = $1;
+		$header =~ s/^\s+//;
+		print "\n/* $header */\n";
+		next;
+	}

ITYM "Emit" not "Omit"?

regards, tom lane

#32Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#31)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

I wrote:

Just in a quick read-through of the patches, the only things I noticed

Oh, a third thing: the patch places errcodes.txt under src/include,
which does not seem even approximately right. src/backend/utils
seems like a saner place for it.

regards, tom lane

#33Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#32)
Re: autogenerating error code lists (was Re: [COMMITTERS] pgsql: Add foreign data wrapper error code values for SQL/MED.)

On Sun, Jan 30, 2011 at 6:27 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I wrote:

Just in a quick read-through of the patches, the only things I noticed

Oh, a third thing: the patch places errcodes.txt under src/include,
which does not seem even approximately right.  src/backend/utils
seems like a saner place for it.

All right, committed after fixing merge conflicts and, I hope, taking
sensible actions based on your comments.

Oh, shoot, I forgot to add the copyright notice to errcodes.txt. Let
me fix that...

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company