Skip to content

Commit d5c7ec7

Browse files
committed
Added Postgres 12 errors
1 parent 8f11821 commit d5c7ec7

File tree

7 files changed

+40
-11
lines changed

7 files changed

+40
-11
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ What's new in psycopg 2.8.4
77
- Don't swallow keyboard interrupts on connect when a password is specified
88
in the connection string (:ticket:`#898`).
99
- Fixed int overflow for large values in `~psycopg2.extensions.Column.table_oid`
10-
and `~psycopg2.extensions.Column.type_code` (:ticket:`961).
10+
and `~psycopg2.extensions.Column.type_code` (:ticket:`961`).
11+
- `~psycopg2.errorcodes` map and `~psycopg2.errors` classes updated to
12+
PostgreSQL 12.
1113

1214

1315
What's new in psycopg 2.8.3

doc/src/errorcodes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ An example of the available constants defined in the module:
5050
'42P01'
5151

5252
Constants representing all the error values defined by PostgreSQL versions
53-
between 8.1 and 11 are included in the module.
53+
between 8.1 and 12 are included in the module.
5454

5555

5656
.. autofunction:: lookup(code)

doc/src/errors.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
.. versionadded:: 2.8
1212

13+
.. versionchanged:: 2.8.4 added errors introduced in PostgreSQL 12
14+
1315
This module exposes the classes psycopg raises upon receiving an error from
1416
the database with a :sql:`SQLSTATE` value attached (available in the
1517
`~psycopg2.Error.pgcode` attribute). The content of the module is generated
1618
from the PostgreSQL source code and includes classes for every error defined
17-
by PostgreSQL in versions between 9.1 and 11.
19+
by PostgreSQL in versions between 9.1 and 12.
1820

1921
Every class in the module is named after what referred as "condition name" `in
2022
the documentation`__, converted to CamelCase: e.g. the error 22012,

lib/errorcodes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ def lookup(code, _cache={}):
205205
ARRAY_SUBSCRIPT_ERROR = '2202E'
206206
INVALID_TABLESAMPLE_REPEAT = '2202G'
207207
INVALID_TABLESAMPLE_ARGUMENT = '2202H'
208+
DUPLICATE_JSON_OBJECT_KEY_VALUE = '22030'
209+
INVALID_JSON_TEXT = '22032'
210+
INVALID_SQL_JSON_SUBSCRIPT = '22033'
211+
MORE_THAN_ONE_SQL_JSON_ITEM = '22034'
212+
NO_SQL_JSON_ITEM = '22035'
213+
NON_NUMERIC_SQL_JSON_ITEM = '22036'
214+
NON_UNIQUE_KEYS_IN_A_JSON_OBJECT = '22037'
215+
SINGLETON_SQL_JSON_ITEM_REQUIRED = '22038'
216+
SQL_JSON_ARRAY_NOT_FOUND = '22039'
217+
SQL_JSON_MEMBER_NOT_FOUND = '2203A'
218+
SQL_JSON_NUMBER_NOT_FOUND = '2203B'
219+
SQL_JSON_OBJECT_NOT_FOUND = '2203C'
220+
TOO_MANY_JSON_ARRAY_ELEMENTS = '2203D'
221+
TOO_MANY_JSON_OBJECT_MEMBERS = '2203E'
222+
SQL_JSON_SCALAR_REQUIRED = '2203F'
208223
FLOATING_POINT_EXCEPTION = '22P01'
209224
INVALID_TEXT_REPRESENTATION = '22P02'
210225
INVALID_BINARY_REPRESENTATION = '22P03'

psycopg/sqlstate_errors.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@
9595
{"2202E", "ArraySubscriptError"},
9696
{"2202G", "InvalidTablesampleRepeat"},
9797
{"2202H", "InvalidTablesampleArgument"},
98+
{"22030", "DuplicateJsonObjectKeyValue"},
99+
{"22032", "InvalidJsonText"},
100+
{"22033", "InvalidSqlJsonSubscript"},
101+
{"22034", "MoreThanOneSqlJsonItem"},
102+
{"22035", "NoSqlJsonItem"},
103+
{"22036", "NonNumericSqlJsonItem"},
104+
{"22037", "NonUniqueKeysInAJsonObject"},
105+
{"22038", "SingletonSqlJsonItemRequired"},
106+
{"22039", "SqlJsonArrayNotFound"},
107+
{"2203A", "SqlJsonMemberNotFound"},
108+
{"2203B", "SqlJsonNumberNotFound"},
109+
{"2203C", "SqlJsonObjectNotFound"},
110+
{"2203D", "TooManyJsonArrayElements"},
111+
{"2203E", "TooManyJsonObjectMembers"},
112+
{"2203F", "SqlJsonScalarRequired"},
98113
{"22P01", "FloatingPointException"},
99114
{"22P02", "InvalidTextRepresentation"},
100115
{"22P03", "InvalidBinaryRepresentation"},
@@ -254,6 +269,7 @@
254269
{"55006", "ObjectInUse"},
255270
{"55P02", "CantChangeRuntimeParam"},
256271
{"55P03", "LockNotAvailable"},
272+
{"55P04", "UnsafeNewEnumValueUsage"},
257273

258274
/* Class 57 - Operator Intervention */
259275
{"57000", "OperatorIntervention"},

scripts/make_errorcodes.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main():
3333
file_start = read_base_file(filename)
3434
# If you add a version to the list fix the docs (in errorcodes.rst)
3535
classes, errors = fetch_errors(
36-
['9.1', '9.2', '9.3', '9.4', '9.5', '9.6', '10', '11'])
36+
['9.1', '9.2', '9.3', '9.4', '9.5', '9.6', '10', '11', '12'])
3737

3838
f = open(filename, "w")
3939
for line in file_start:
@@ -109,12 +109,6 @@ def fetch_errors(versions):
109109
# https://github.com/postgres/postgres/commit/12f87b2c82
110110
errors['22']['22020'] = 'INVALID_LIMIT_VALUE'
111111

112-
# TODO: this error was added in PG 10 beta 1 but dropped in the
113-
# final release. It doesn't harm leaving it in the file. Check if it
114-
# will be added back in PG 12.
115-
# https://github.com/postgres/postgres/commit/28e0727076
116-
errors['55']['55P04'] = 'UNSAFE_NEW_ENUM_VALUE_USAGE'
117-
118112
for c, cerrs in e1.items():
119113
errors[c].update(cerrs)
120114

scripts/make_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030

3131
# If you add a version to the list fix the docs (in errors.rst)
3232
classes, errors = fetch_errors(
33-
['9.1', '9.2', '9.3', '9.4', '9.5', '9.6', '10', '11'])
33+
['9.1', '9.2', '9.3', '9.4', '9.5', '9.6', '10', '11', '12'])
3434

3535
f = open(filename, "w")
3636
print("/*\n * Autogenerated by 'scripts/make_errors.py'.\n */\n", file=f)

0 commit comments

Comments
 (0)