Skip to content

Commit c9a5860

Browse files
author
Amit Kapila
committed
Throw ERROR when publish_generated_columns is specified without a value.
Previously, specifying the publication option 'publish_generated_columns' without an explicit value would incorrectly default to 'stored', which is not the intended behavior. This patch fixes the issue by raising an ERROR when no value is provided for 'publish_generated_columns', ensuring that users must explicitly specify a valid option. Author: Peter Smith <smithpb2250@gmail.com> Reviewed-by: vignesh C <vignesh21@gmail.com> Backpatch-through: 18, where it was introduced Discussion: https://postgr.es/m/CAHut+PsCUCWiEKmB10DxhoPfXbF6jw5RD9ib2LuaQeA_XraW7w@mail.gmail.com
1 parent 1469e31 commit c9a5860

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

src/backend/commands/publicationcmds.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,20 +2113,20 @@ AlterPublicationOwner_oid(Oid pubid, Oid newOwnerId)
21132113
static char
21142114
defGetGeneratedColsOption(DefElem *def)
21152115
{
2116-
char *sval;
2116+
char *sval = "";
21172117

21182118
/*
2119-
* If no parameter value given, assume "stored" is meant.
2119+
* A parameter value is required.
21202120
*/
2121-
if (!def->arg)
2122-
return PUBLISH_GENCOLS_STORED;
2123-
2124-
sval = defGetString(def);
2121+
if (def->arg)
2122+
{
2123+
sval = defGetString(def);
21252124

2126-
if (pg_strcasecmp(sval, "none") == 0)
2127-
return PUBLISH_GENCOLS_NONE;
2128-
if (pg_strcasecmp(sval, "stored") == 0)
2129-
return PUBLISH_GENCOLS_STORED;
2125+
if (pg_strcasecmp(sval, "none") == 0)
2126+
return PUBLISH_GENCOLS_NONE;
2127+
if (pg_strcasecmp(sval, "stored") == 0)
2128+
return PUBLISH_GENCOLS_STORED;
2129+
}
21302130

21312131
ereport(ERROR,
21322132
errcode(ERRCODE_SYNTAX_ERROR),

src/test/regress/expected/publication.out

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ LINE 1: ...pub_xxx WITH (publish_generated_columns = stored, publish_ge...
3636
CREATE PUBLICATION testpub_xxx WITH (publish_generated_columns = foo);
3737
ERROR: invalid value for publication parameter "publish_generated_columns": "foo"
3838
DETAIL: Valid values are "none" and "stored".
39+
CREATE PUBLICATION testpub_xxx WITH (publish_generated_columns);
40+
ERROR: invalid value for publication parameter "publish_generated_columns": ""
41+
DETAIL: Valid values are "none" and "stored".
3942
\dRp
4043
List of publications
4144
Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Generated columns | Via root
@@ -1844,8 +1847,7 @@ DROP SCHEMA sch1 cascade;
18441847
DROP SCHEMA sch2 cascade;
18451848
-- ======================================================
18461849
-- Test the 'publish_generated_columns' parameter with the following values:
1847-
-- 'stored', 'none', and the default (no value specified), which defaults to
1848-
-- 'stored'.
1850+
-- 'stored', 'none'.
18491851
SET client_min_messages = 'ERROR';
18501852
CREATE PUBLICATION pub1 FOR ALL TABLES WITH (publish_generated_columns = stored);
18511853
\dRp+ pub1
@@ -1863,17 +1865,8 @@ CREATE PUBLICATION pub2 FOR ALL TABLES WITH (publish_generated_columns = none);
18631865
regress_publication_user | t | t | t | t | t | none | f
18641866
(1 row)
18651867

1866-
CREATE PUBLICATION pub3 FOR ALL TABLES WITH (publish_generated_columns);
1867-
\dRp+ pub3
1868-
Publication pub3
1869-
Owner | All tables | Inserts | Updates | Deletes | Truncates | Generated columns | Via root
1870-
--------------------------+------------+---------+---------+---------+-----------+-------------------+----------
1871-
regress_publication_user | t | t | t | t | t | stored | f
1872-
(1 row)
1873-
18741868
DROP PUBLICATION pub1;
18751869
DROP PUBLICATION pub2;
1876-
DROP PUBLICATION pub3;
18771870
-- Test the 'publish_generated_columns' parameter as 'none' and 'stored' for
18781871
-- different scenarios with/without generated columns in column lists.
18791872
CREATE TABLE gencols (a int, gen1 int GENERATED ALWAYS AS (a * 2) STORED);

src/test/regress/sql/publication.sql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CREATE PUBLICATION testpub_xxx WITH (publish = 'cluster, vacuum');
2626
CREATE PUBLICATION testpub_xxx WITH (publish_via_partition_root = 'true', publish_via_partition_root = '0');
2727
CREATE PUBLICATION testpub_xxx WITH (publish_generated_columns = stored, publish_generated_columns = none);
2828
CREATE PUBLICATION testpub_xxx WITH (publish_generated_columns = foo);
29+
CREATE PUBLICATION testpub_xxx WITH (publish_generated_columns);
2930

3031
\dRp
3132

@@ -1183,19 +1184,15 @@ DROP SCHEMA sch2 cascade;
11831184
-- ======================================================
11841185

11851186
-- Test the 'publish_generated_columns' parameter with the following values:
1186-
-- 'stored', 'none', and the default (no value specified), which defaults to
1187-
-- 'stored'.
1187+
-- 'stored', 'none'.
11881188
SET client_min_messages = 'ERROR';
11891189
CREATE PUBLICATION pub1 FOR ALL TABLES WITH (publish_generated_columns = stored);
11901190
\dRp+ pub1
11911191
CREATE PUBLICATION pub2 FOR ALL TABLES WITH (publish_generated_columns = none);
11921192
\dRp+ pub2
1193-
CREATE PUBLICATION pub3 FOR ALL TABLES WITH (publish_generated_columns);
1194-
\dRp+ pub3
11951193

11961194
DROP PUBLICATION pub1;
11971195
DROP PUBLICATION pub2;
1198-
DROP PUBLICATION pub3;
11991196

12001197
-- Test the 'publish_generated_columns' parameter as 'none' and 'stored' for
12011198
-- different scenarios with/without generated columns in column lists.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy