use SQL standard error code for nextval

Started by Peter Eisentrautalmost 9 years ago5 messages
#1Peter Eisentraut
peter.eisentraut@2ndquadrant.com
1 attachment(s)

The SQL standard defines a separate error code for nextval exhausting
the sequence space. I haven't found any discussion of this in the
archives, so it seems this was just not considered or not yet in
existence when the error codes were introduced. Here is a patch to
correct it.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Use-SQL-standard-error-code-for-nextval.patchtext/x-patch; name=0001-Use-SQL-standard-error-code-for-nextval.patchDownload
From db87587803458c6ade81819441321e8761d5ef7a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 28 Feb 2017 15:14:14 -0500
Subject: [PATCH] Use SQL standard error code for nextval

---
 src/backend/commands/sequence.c | 4 ++--
 src/backend/utils/errcodes.txt  | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index e0df642254..5820fee5a3 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -694,7 +694,7 @@ nextval_internal(Oid relid)
 
 					snprintf(buf, sizeof(buf), INT64_FORMAT, maxv);
 					ereport(ERROR,
-						  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+						  (errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED),
 						   errmsg("nextval: reached maximum value of sequence \"%s\" (%s)",
 								  RelationGetRelationName(seqrel), buf)));
 				}
@@ -717,7 +717,7 @@ nextval_internal(Oid relid)
 
 					snprintf(buf, sizeof(buf), INT64_FORMAT, minv);
 					ereport(ERROR,
-						  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+						  (errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED),
 						   errmsg("nextval: reached minimum value of sequence \"%s\" (%s)",
 								  RelationGetRelationName(seqrel), buf)));
 				}
diff --git a/src/backend/utils/errcodes.txt b/src/backend/utils/errcodes.txt
index 46aadd76f7..b6e0e987a8 100644
--- a/src/backend/utils/errcodes.txt
+++ b/src/backend/utils/errcodes.txt
@@ -188,6 +188,7 @@ Section: Class 22 - Data Exception
 22004    E    ERRCODE_NULL_VALUE_NOT_ALLOWED                                 null_value_not_allowed
 22002    E    ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER                      null_value_no_indicator_parameter
 22003    E    ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE                             numeric_value_out_of_range
+2200H    E    ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED                      sequence_generator_limit_exceeded
 22026    E    ERRCODE_STRING_DATA_LENGTH_MISMATCH                            string_data_length_mismatch
 22001    E    ERRCODE_STRING_DATA_RIGHT_TRUNCATION                           string_data_right_truncation
 22011    E    ERRCODE_SUBSTRING_ERROR                                        substring_error
-- 
2.12.0

#2Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Peter Eisentraut (#1)
Re: use SQL standard error code for nextval

On 2/28/17 22:15, Peter Eisentraut wrote:

The SQL standard defines a separate error code for nextval exhausting
the sequence space. I haven't found any discussion of this in the
archives, so it seems this was just not considered or not yet in
existence when the error codes were introduced. Here is a patch to
correct it.

committed

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Mark Dilger
hornschnorter@gmail.com
In reply to: Peter Eisentraut (#2)
Re: use SQL standard error code for nextval

On Mar 9, 2017, at 7:59 AM, Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

On 2/28/17 22:15, Peter Eisentraut wrote:

The SQL standard defines a separate error code for nextval exhausting
the sequence space. I haven't found any discussion of this in the
archives, so it seems this was just not considered or not yet in
existence when the error codes were introduced. Here is a patch to
correct it.

committed

Perhaps you should add something to the release notes. Somebody could be
testing for the old error code.

Mark Dilger

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Mark Dilger (#3)
Re: use SQL standard error code for nextval

On 3/9/17 12:27, Mark Dilger wrote:

Perhaps you should add something to the release notes. Somebody could be
testing for the old error code.

The release notes will be written when the release is prepared.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Mark Dilger (#3)
Re: use SQL standard error code for nextval

Mark Dilger <hornschnorter@gmail.com> writes:

On Mar 9, 2017, at 7:59 AM, Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:
On 2/28/17 22:15, Peter Eisentraut wrote:

The SQL standard defines a separate error code for nextval exhausting
the sequence space. I haven't found any discussion of this in the
archives, so it seems this was just not considered or not yet in
existence when the error codes were introduced. Here is a patch to
correct it.

Perhaps you should add something to the release notes. Somebody could be
testing for the old error code.

The release notes for v10 aren't going to be drafted for months yet.
When they are, hopefully the writer will notice that this should be
listed as an incompatible change. That's not the responsibility
of this commit, although it would've been better if the commit log
entry explicitly pointed out that it's an incompatible change.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers