Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d36228a

Browse files
committed
Improve wording of two error messages related to generated columns.
Clarify that you can "insert" into a generated column as long as what you're inserting is a DEFAULT placeholder. Also, use ERRCODE_GENERATED_ALWAYS in place of ERRCODE_SYNTAX_ERROR; there doesn't seem to be any reason to use the less specific errcode. Discussion: https://postgr.es/m/9q0sgcr416t.fsf@gmx.us
1 parent fe05129 commit d36228a

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

src/backend/rewrite/rewriteHandler.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ rewriteTargetListIU(List *targetList,
861861
if (!apply_default)
862862
ereport(ERROR,
863863
(errcode(ERRCODE_GENERATED_ALWAYS),
864-
errmsg("cannot insert into column \"%s\"",
864+
errmsg("cannot insert a non-DEFAULT value into column \"%s\"",
865865
NameStr(att_tup->attname)),
866866
errdetail("Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
867867
NameStr(att_tup->attname)),
@@ -899,8 +899,8 @@ rewriteTargetListIU(List *targetList,
899899

900900
if (!apply_default)
901901
ereport(ERROR,
902-
(errcode(ERRCODE_SYNTAX_ERROR),
903-
errmsg("cannot insert into column \"%s\"",
902+
(errcode(ERRCODE_GENERATED_ALWAYS),
903+
errmsg("cannot insert a non-DEFAULT value into column \"%s\"",
904904
NameStr(att_tup->attname)),
905905
errdetail("Column \"%s\" is a generated column.",
906906
NameStr(att_tup->attname))));
@@ -923,17 +923,20 @@ rewriteTargetListIU(List *targetList,
923923
*/
924924
if (commandType == CMD_UPDATE)
925925
{
926-
if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS && new_tle && !apply_default)
926+
if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS &&
927+
new_tle && !apply_default)
927928
ereport(ERROR,
928929
(errcode(ERRCODE_GENERATED_ALWAYS),
929-
errmsg("column \"%s\" can only be updated to DEFAULT", NameStr(att_tup->attname)),
930+
errmsg("column \"%s\" can only be updated to DEFAULT",
931+
NameStr(att_tup->attname)),
930932
errdetail("Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
931933
NameStr(att_tup->attname))));
932934

933935
if (att_tup->attgenerated && new_tle && !apply_default)
934936
ereport(ERROR,
935-
(errcode(ERRCODE_SYNTAX_ERROR),
936-
errmsg("column \"%s\" can only be updated to DEFAULT", NameStr(att_tup->attname)),
937+
(errcode(ERRCODE_GENERATED_ALWAYS),
938+
errmsg("column \"%s\" can only be updated to DEFAULT",
939+
NameStr(att_tup->attname)),
937940
errdetail("Column \"%s\" is a generated column.",
938941
NameStr(att_tup->attname))));
939942
}

src/test/regress/expected/generated.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ LINE 1: ...E gtest_err_8 (a int PRIMARY KEY, b int GENERATED BY DEFAULT...
9393
INSERT INTO gtest1 VALUES (1);
9494
INSERT INTO gtest1 VALUES (2, DEFAULT); -- ok
9595
INSERT INTO gtest1 VALUES (3, 33); -- error
96-
ERROR: cannot insert into column "b"
96+
ERROR: cannot insert a non-DEFAULT value into column "b"
9797
DETAIL: Column "b" is a generated column.
9898
INSERT INTO gtest1 VALUES (3, 33), (4, 44); -- error
99-
ERROR: cannot insert into column "b"
99+
ERROR: cannot insert a non-DEFAULT value into column "b"
100100
DETAIL: Column "b" is a generated column.
101101
INSERT INTO gtest1 VALUES (3, DEFAULT), (4, 44); -- error
102-
ERROR: cannot insert into column "b"
102+
ERROR: cannot insert a non-DEFAULT value into column "b"
103103
DETAIL: Column "b" is a generated column.
104104
INSERT INTO gtest1 VALUES (3, 33), (4, DEFAULT); -- error
105-
ERROR: cannot insert into column "b"
105+
ERROR: cannot insert a non-DEFAULT value into column "b"
106106
DETAIL: Column "b" is a generated column.
107107
INSERT INTO gtest1 VALUES (3, DEFAULT), (4, DEFAULT); -- ok
108108
SELECT * FROM gtest1 ORDER BY a;
@@ -193,25 +193,25 @@ SELECT * FROM gtest1v;
193193
(1 row)
194194

195195
INSERT INTO gtest1v VALUES (4, 8); -- error
196-
ERROR: cannot insert into column "b"
196+
ERROR: cannot insert a non-DEFAULT value into column "b"
197197
DETAIL: Column "b" is a generated column.
198198
INSERT INTO gtest1v VALUES (5, DEFAULT); -- ok
199199
INSERT INTO gtest1v VALUES (6, 66), (7, 77); -- error
200-
ERROR: cannot insert into column "b"
200+
ERROR: cannot insert a non-DEFAULT value into column "b"
201201
DETAIL: Column "b" is a generated column.
202202
INSERT INTO gtest1v VALUES (6, DEFAULT), (7, 77); -- error
203-
ERROR: cannot insert into column "b"
203+
ERROR: cannot insert a non-DEFAULT value into column "b"
204204
DETAIL: Column "b" is a generated column.
205205
INSERT INTO gtest1v VALUES (6, 66), (7, DEFAULT); -- error
206-
ERROR: cannot insert into column "b"
206+
ERROR: cannot insert a non-DEFAULT value into column "b"
207207
DETAIL: Column "b" is a generated column.
208208
INSERT INTO gtest1v VALUES (6, DEFAULT), (7, DEFAULT); -- ok
209209
ALTER VIEW gtest1v ALTER COLUMN b SET DEFAULT 100;
210210
INSERT INTO gtest1v VALUES (8, DEFAULT); -- error
211-
ERROR: cannot insert into column "b"
211+
ERROR: cannot insert a non-DEFAULT value into column "b"
212212
DETAIL: Column "b" is a generated column.
213213
INSERT INTO gtest1v VALUES (8, DEFAULT), (9, DEFAULT); -- error
214-
ERROR: cannot insert into column "b"
214+
ERROR: cannot insert a non-DEFAULT value into column "b"
215215
DETAIL: Column "b" is a generated column.
216216
SELECT * FROM gtest1v;
217217
a | b

src/test/regress/expected/identity.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ SELECT * FROM itest4;
107107
-- VALUES RTEs
108108
CREATE TABLE itest5 (a int generated always as identity, b text);
109109
INSERT INTO itest5 VALUES (1, 'a'); -- error
110-
ERROR: cannot insert into column "a"
110+
ERROR: cannot insert a non-DEFAULT value into column "a"
111111
DETAIL: Column "a" is an identity column defined as GENERATED ALWAYS.
112112
HINT: Use OVERRIDING SYSTEM VALUE to override.
113113
INSERT INTO itest5 VALUES (DEFAULT, 'a'); -- ok
114114
INSERT INTO itest5 VALUES (2, 'b'), (3, 'c'); -- error
115-
ERROR: cannot insert into column "a"
115+
ERROR: cannot insert a non-DEFAULT value into column "a"
116116
DETAIL: Column "a" is an identity column defined as GENERATED ALWAYS.
117117
HINT: Use OVERRIDING SYSTEM VALUE to override.
118118
INSERT INTO itest5 VALUES (DEFAULT, 'b'), (3, 'c'); -- error
119-
ERROR: cannot insert into column "a"
119+
ERROR: cannot insert a non-DEFAULT value into column "a"
120120
DETAIL: Column "a" is an identity column defined as GENERATED ALWAYS.
121121
HINT: Use OVERRIDING SYSTEM VALUE to override.
122122
INSERT INTO itest5 VALUES (2, 'b'), (DEFAULT, 'c'); -- error
123-
ERROR: cannot insert into column "a"
123+
ERROR: cannot insert a non-DEFAULT value into column "a"
124124
DETAIL: Column "a" is an identity column defined as GENERATED ALWAYS.
125125
HINT: Use OVERRIDING SYSTEM VALUE to override.
126126
INSERT INTO itest5 VALUES (DEFAULT, 'b'), (DEFAULT, 'c'); -- ok
@@ -197,7 +197,7 @@ SELECT * FROM itest1;
197197
-- GENERATED ALWAYS
198198
-- This is an error:
199199
INSERT INTO itest2 VALUES (10, 'xyz');
200-
ERROR: cannot insert into column "a"
200+
ERROR: cannot insert a non-DEFAULT value into column "a"
201201
DETAIL: Column "a" is an identity column defined as GENERATED ALWAYS.
202202
HINT: Use OVERRIDING SYSTEM VALUE to override.
203203
-- This inserts the row as presented:
@@ -313,7 +313,7 @@ SELECT * FROM itestv10;
313313
(4 rows)
314314

315315
INSERT INTO itestv11 VALUES (10, 'xyz');
316-
ERROR: cannot insert into column "a"
316+
ERROR: cannot insert a non-DEFAULT value into column "a"
317317
DETAIL: Column "a" is an identity column defined as GENERATED ALWAYS.
318318
HINT: Use OVERRIDING SYSTEM VALUE to override.
319319
INSERT INTO itestv11 OVERRIDING SYSTEM VALUE VALUES (11, 'xyz');

src/test/regress/expected/updatable_views.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,10 +1475,10 @@ INSERT INTO rw_view1 (id) VALUES (2);
14751475
INSERT INTO base_tbl (id, idplus1) VALUES (3, DEFAULT);
14761476
INSERT INTO rw_view1 (id, idplus1) VALUES (4, DEFAULT);
14771477
INSERT INTO base_tbl (id, idplus1) VALUES (5, 6); -- error
1478-
ERROR: cannot insert into column "idplus1"
1478+
ERROR: cannot insert a non-DEFAULT value into column "idplus1"
14791479
DETAIL: Column "idplus1" is a generated column.
14801480
INSERT INTO rw_view1 (id, idplus1) VALUES (6, 7); -- error
1481-
ERROR: cannot insert into column "idplus1"
1481+
ERROR: cannot insert a non-DEFAULT value into column "idplus1"
14821482
DETAIL: Column "idplus1" is a generated column.
14831483
SELECT * FROM base_tbl;
14841484
id | idplus1

0 commit comments

Comments
 (0)