Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa12781

Browse files
Improve publication error messages
Commit81d5995 introduced more fine-grained errormessages forincorrect relkinds for publication, while unlogged and temporarytables were reported with using the same message. This providesseparate error messages for these types of relpersistence.Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>Reviewed-by: Jeevan Ladhe <jeevan.ladhe@enterprisedb.com>Reviewed-by: Euler Taveira <euler@eulerto.com>Discussion:https://postgr.es/m/CALj2ACW9S=AswyQHjtO6WMcsergMkCBTtzXGrM8DX26DzfeTLQ@mail.gmail.com
1 parent3374a87 commitaa12781

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

‎contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work again
256256
ANALYZE ft1;
257257
ALTER FOREIGN TABLE ft2 OPTIONS (use_remote_estimate 'true');
258258
-- ===================================================================
259+
-- test error case for create publication on foreign table
260+
-- ===================================================================
261+
CREATE PUBLICATION testpub_ftbl FOR TABLE ft1; -- should fail
262+
ERROR: cannot add relation "ft1" to publication
263+
DETAIL: This operation is not supported for foreign tables.
264+
-- ===================================================================
259265
-- simple queries
260266
-- ===================================================================
261267
-- single table without alias

‎contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work again
247247
ANALYZE ft1;
248248
ALTER FOREIGN TABLE ft2 OPTIONS (use_remote_estimate'true');
249249

250+
-- ===================================================================
251+
-- test error case for create publication on foreign table
252+
-- ===================================================================
253+
CREATE PUBLICATION testpub_ftbl FOR TABLE ft1;-- should fail
254+
250255
-- ===================================================================
251256
-- simple queries
252257
-- ===================================================================

‎src/backend/catalog/pg_publication.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@ check_publication_add_relation(Relation targetrel)
7070
errdetail("This operation is not supported for system tables.")));
7171

7272
/* UNLOGGED and TEMP relations cannot be part of publication. */
73-
if (!RelationIsPermanent(targetrel))
73+
if (targetrel->rd_rel->relpersistence==RELPERSISTENCE_TEMP)
7474
ereport(ERROR,
7575
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7676
errmsg("cannot add relation \"%s\" to publication",
7777
RelationGetRelationName(targetrel)),
78-
errdetail("Temporary and unlogged relations cannot be replicated.")));
78+
errdetail("This operation is not supported for temporary tables.")));
79+
elseif (targetrel->rd_rel->relpersistence==RELPERSISTENCE_UNLOGGED)
80+
ereport(ERROR,
81+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
82+
errmsg("cannot add relation \"%s\" to publication",
83+
RelationGetRelationName(targetrel)),
84+
errdetail("This operation is not supported for unlogged tables.")));
7985
}
8086

8187
/*

‎src/test/regress/expected/publication.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ DROP TABLE testpub_tbl4;
258258
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
259259
ERROR: cannot add relation "testpub_view" to publication
260260
DETAIL: This operation is not supported for views.
261+
CREATE TEMPORARY TABLE testpub_temptbl(a int);
262+
-- fail - temporary table
263+
CREATE PUBLICATION testpub_fortemptbl FOR TABLE testpub_temptbl;
264+
ERROR: cannot add relation "testpub_temptbl" to publication
265+
DETAIL: This operation is not supported for temporary tables.
266+
DROP TABLE testpub_temptbl;
267+
CREATE UNLOGGED TABLE testpub_unloggedtbl(a int);
268+
-- fail - unlogged table
269+
CREATE PUBLICATION testpub_forunloggedtbl FOR TABLE testpub_unloggedtbl;
270+
ERROR: cannot add relation "testpub_unloggedtbl" to publication
271+
DETAIL: This operation is not supported for unlogged tables.
272+
DROP TABLE testpub_unloggedtbl;
273+
-- fail - system table
274+
CREATE PUBLICATION testpub_forsystemtbl FOR TABLE pg_publication;
275+
ERROR: cannot add relation "pg_publication" to publication
276+
DETAIL: This operation is not supported for system tables.
261277
SET client_min_messages = 'ERROR';
262278
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk;
263279
RESET client_min_messages;

‎src/test/regress/sql/publication.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ DROP TABLE testpub_tbl4;
150150

151151
-- fail - view
152152
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
153+
154+
CREATE TEMPORARY TABLE testpub_temptbl(aint);
155+
-- fail - temporary table
156+
CREATE PUBLICATION testpub_fortemptbl FOR TABLE testpub_temptbl;
157+
DROPTABLE testpub_temptbl;
158+
159+
CREATE UNLOGGED TABLE testpub_unloggedtbl(aint);
160+
-- fail - unlogged table
161+
CREATE PUBLICATION testpub_forunloggedtbl FOR TABLE testpub_unloggedtbl;
162+
DROPTABLE testpub_unloggedtbl;
163+
164+
-- fail - system table
165+
CREATE PUBLICATION testpub_forsystemtbl FOR TABLE pg_publication;
166+
153167
SET client_min_messages='ERROR';
154168
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1,pub_test.testpub_nopk;
155169
RESET client_min_messages;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp